vscode-xml icon indicating copy to clipboard operation
vscode-xml copied to clipboard

"Get Current XPath" returns wrong result

Open lnrd96 opened this issue 5 years ago • 5 comments

Description The index returned does not exist. Also the resulting xpath does not exist as an input to "Evaluate Current XPath". I could not (yet) find out in which context this bug does or does not occur.

F.e.: /root/element/subelement/thiselementdoesnotexist[6]/leafelement The element is actually at index [2].

Extension Version 2.5.0

VS Code Version 1.45.1

Operating System Darwin x64 19.4.0

lnrd96 avatar Jun 03 '20 12:06 lnrd96

The "get current XPath" implementation is pretty naïve and could use an overhaul. If you could provide an example XML document that can be used to reproduce, that would be helpful when I revisit this feature. Thanks!

DotJoshJohnson avatar Jul 07 '20 03:07 DotJoshJohnson

I confirm the issue

STEPS TO REPRODUCE

Find xpath of openEHR-EHR-ADMIN_ENTRY.minimal.v1 in below XML document

<template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.openehr.org/v1">
  <language>
    <terminology_id>
      <value>ISO_639-1</value>
    </terminology_id>
    <code_string>en</code_string>
  </language>
  <description>
    <original_author id="Original Author">Not Specified</original_author>
    <lifecycle_state>Initial</lifecycle_state>
    <other_details id="MetaDataSet:Sample Set ">Template metadata sample set </other_details>
    <other_details id="Acknowledgements"/>
    <other_details id="Business Process Level"/>
    <other_details id="Care setting"/>
    <other_details id="Client group"/>
    <other_details id="Clinical Record Element"/>
    <other_details id="Copyright"/>
    <other_details id="Issues"/>
    <other_details id="Owner"/>
    <other_details id="Sign off"/>
    <other_details id="Speciality"/>
    <other_details id="User roles"/>
    <details>
      <language>
        <terminology_id>
          <value>ISO_639-1</value>
        </terminology_id>
        <code_string>en</code_string>
      </language>
      <purpose>Not Specified</purpose>
    </details>
  </description>
  <uid>
    <value>c53b4d8d-23b6-4333-b7f5-a2a5ca98278b</value>
  </uid>
  <template_id>
    <value>minimal_admin.en.v1</value>
  </template_id>
  <concept>Minimal admin</concept>
  <definition>
    <rm_type_name>COMPOSITION</rm_type_name>
    <occurrences>
      <lower_included>true</lower_included>
      <upper_included>true</upper_included>
      <lower_unbounded>false</lower_unbounded>
      <upper_unbounded>false</upper_unbounded>
      <lower>1</lower>
      <upper>1</upper>
    </occurrences>
    <node_id>at0000</node_id>
    <attributes xsi:type="C_SINGLE_ATTRIBUTE">
      <rm_attribute_name>category</rm_attribute_name>
      <existence>
        <lower_included>true</lower_included>
        <upper_included>true</upper_included>
        <lower_unbounded>false</lower_unbounded>
        <upper_unbounded>false</upper_unbounded>
        <lower>1</lower>
        <upper>1</upper>
      </existence>
      <children xsi:type="C_COMPLEX_OBJECT">
        <rm_type_name>DV_CODED_TEXT</rm_type_name>
        <occurrences>
          <lower_included>true</lower_included>
          <upper_included>true</upper_included>
          <lower_unbounded>false</lower_unbounded>
          <upper_unbounded>false</upper_unbounded>
          <lower>1</lower>
          <upper>1</upper>
        </occurrences>
        <node_id/>
        <attributes xsi:type="C_SINGLE_ATTRIBUTE">
          <rm_attribute_name>defining_code</rm_attribute_name>
          <existence>
            <lower_included>true</lower_included>
            <upper_included>true</upper_included>
            <lower_unbounded>false</lower_unbounded>
            <upper_unbounded>false</upper_unbounded>
            <lower>1</lower>
            <upper>1</upper>
          </existence>
          <children xsi:type="C_CODE_PHRASE">
            <rm_type_name>CODE_PHRASE</rm_type_name>
            <occurrences>
              <lower_included>true</lower_included>
              <upper_included>true</upper_included>
              <lower_unbounded>false</lower_unbounded>
              <upper_unbounded>false</upper_unbounded>
              <lower>1</lower>
              <upper>1</upper>
            </occurrences>
            <node_id/>
            <terminology_id>
              <value>openehr</value>
            </terminology_id>
            <code_list>433</code_list>
          </children>
        </attributes>
      </children>
    </attributes>
    <attributes xsi:type="C_MULTIPLE_ATTRIBUTE">
      <rm_attribute_name>content</rm_attribute_name>
      <existence>
        <lower_included>true</lower_included>
        <upper_included>true</upper_included>
        <lower_unbounded>false</lower_unbounded>
        <upper_unbounded>false</upper_unbounded>
        <lower>0</lower>
        <upper>1</upper>
      </existence>
      <children xsi:type="C_ARCHETYPE_ROOT">
        <rm_type_name>ADMIN_ENTRY</rm_type_name>
        <occurrences>
          <lower_included>true</lower_included>
          <lower_unbounded>false</lower_unbounded>
          <upper_unbounded>true</upper_unbounded>
          <lower>0</lower>
        </occurrences>
        <node_id>at0000</node_id>
        <attributes xsi:type="C_SINGLE_ATTRIBUTE">
          <rm_attribute_name>data</rm_attribute_name>
          <existence>
            <lower_included>true</lower_included>
            <upper_included>true</upper_included>
            <lower_unbounded>false</lower_unbounded>
            <upper_unbounded>false</upper_unbounded>
            <lower>1</lower>
            <upper>1</upper>
          </existence>
          <children xsi:type="C_COMPLEX_OBJECT">
            <rm_type_name>ITEM_TREE</rm_type_name>
            <occurrences>
              <lower_included>true</lower_included>
              <upper_included>true</upper_included>
              <lower_unbounded>false</lower_unbounded>
              <upper_unbounded>false</upper_unbounded>
              <lower>1</lower>
              <upper>1</upper>
            </occurrences>
            <node_id>at0001</node_id>
            <attributes xsi:type="C_MULTIPLE_ATTRIBUTE">
              <rm_attribute_name>items</rm_attribute_name>
              <existence>
                <lower_included>true</lower_included>
                <upper_included>true</upper_included>
                <lower_unbounded>false</lower_unbounded>
                <upper_unbounded>false</upper_unbounded>
                <lower>0</lower>
                <upper>1</upper>
              </existence>
              <children xsi:type="C_COMPLEX_OBJECT">
                <rm_type_name>ELEMENT</rm_type_name>
                <occurrences>
                  <lower_included>true</lower_included>
                  <upper_included>true</upper_included>
                  <lower_unbounded>false</lower_unbounded>
                  <upper_unbounded>false</upper_unbounded>
                  <lower>0</lower>
                  <upper>1</upper>
                </occurrences>
                <node_id>at0002</node_id>
                <attributes xsi:type="C_SINGLE_ATTRIBUTE">
                  <rm_attribute_name>value</rm_attribute_name>
                  <existence>
                    <lower_included>true</lower_included>
                    <upper_included>true</upper_included>
                    <lower_unbounded>false</lower_unbounded>
                    <upper_unbounded>false</upper_unbounded>
                    <lower>0</lower>
                    <upper>1</upper>
                  </existence>
                  <children xsi:type="C_DV_ORDINAL">
                    <rm_type_name>DV_ORDINAL</rm_type_name>
                    <occurrences>
                      <lower_included>true</lower_included>
                      <upper_included>true</upper_included>
                      <lower_unbounded>false</lower_unbounded>
                      <upper_unbounded>false</upper_unbounded>
                      <lower>1</lower>
                      <upper>1</upper>
                    </occurrences>
                    <node_id/>
                    <list>
                      <value>1</value>
                      <symbol>
                        <value/>
                        <defining_code>
                          <terminology_id>
                            <value>local</value>
                          </terminology_id>
                          <code_string>at0003</code_string>
                        </defining_code>
                      </symbol>
                    </list>
                    <list>
                      <value>2</value>
                      <symbol>
                        <value/>
                        <defining_code>
                          <terminology_id>
                            <value>local</value>
                          </terminology_id>
                          <code_string>at0004</code_string>
                        </defining_code>
                      </symbol>
                    </list>
                    <list>
                      <value>3</value>
                      <symbol>
                        <value/>
                        <defining_code>
                          <terminology_id>
                            <value>local</value>
                          </terminology_id>
                          <code_string>at0005</code_string>
                        </defining_code>
                      </symbol>
                    </list>
                  </children>
                </attributes>
              </children>
              <cardinality>
                <is_ordered>false</is_ordered>
                <is_unique>false</is_unique>
                <interval>
                  <lower_included>true</lower_included>
                  <lower_unbounded>false</lower_unbounded>
                  <upper_unbounded>true</upper_unbounded>
                  <lower>0</lower>
                </interval>
              </cardinality>
            </attributes>
          </children>
        </attributes>
        <archetype_id>
          <value>openEHR-EHR-ADMIN_ENTRY.minimal.v1</value>
        </archetype_id>
        <term_definitions code="at0000">
          <items id="description">unknown</items>
          <items id="text">Minimal</items>
        </term_definitions>
        <term_definitions code="at0001">
          <items id="description">@ internal @</items>
          <items id="text">Arbol</items>
        </term_definitions>
        <term_definitions code="at0002">
          <items id="description">*</items>
          <items id="text">ordinal</items>
        </term_definitions>
        <term_definitions code="at0003">
          <items id="description">*</items>
          <items id="text">option 1</items>
        </term_definitions>
        <term_definitions code="at0004">
          <items id="description">*</items>
          <items id="text">option 2</items>
        </term_definitions>
        <term_definitions code="at0005">
          <items id="description">*</items>
          <items id="text">option 3</items>
        </term_definitions>
      </children>
      <cardinality>
        <is_ordered>false</is_ordered>
        <is_unique>false</is_unique>
        <interval>
          <lower_included>true</lower_included>
          <lower_unbounded>false</lower_unbounded>
          <upper_unbounded>true</upper_unbounded>
          <lower>0</lower>
        </interval>
      </cardinality>
    </attributes>
    <archetype_id>
      <value>openEHR-EHR-COMPOSITION.minimal.v1</value>
    </archetype_id>
    <template_id>
      <value>minimal_admin.en.v1</value>
    </template_id>
    <term_definitions code="at0000">
      <items id="description">unknown</items>
      <items id="text">Minimal</items>
    </term_definitions>
  </definition>
</template>

ACTUAL

XML Tools: Get Current XPath returns

/template/definition/attributes[5]/children/archetype_id/value

EXPECTED

XML Tools: Get Current XPath returns

/template/definition/attributes[2]/children/archetype_id/value

wlad avatar Jul 21 '21 14:07 wlad

I would like to see this fixed too. Strangely, if I select the node I am interested in and invoke XML:Goto Path it shows the correct path.

J9zAacNh39Ad7RP avatar Nov 25 '21 00:11 J9zAacNh39Ad7RP

#377

AZN1244 avatar Jan 01 '24 17:01 AZN1244

this bug still exists in 2024...

eneshb avatar Aug 19 '24 13:08 eneshb