3

Having trouble getting the desired output... maybe it's not possible but I'm new to XPath selectors.

I have XML like:

<submission>
    <component type="X">
        <audit>
            <measures>
                <measure id="xyz">
                    <reported>false</reported>
                    <benefit>false</benefit>
                    <data-elements>
                        <data-element id="rate1">
                            <reportable>false</reportable>
                            <comment/>
                        </data-element>
                        <data-element id="rate2">
                            <reportable>false</reportable>
                            <comment/>
                        </data-element>
                        <data-element id="rate3">
                            <reportable>false</reportable>
                            <comment/>
                        </data-element>
                        <data-element id="rate4">
                            <reportable>false</reportable>
                            <comment/>
                        </data-element>
                    </data-elements>
                </measure>
                <measure id="abc">
                    <reported>false</reported>
                    <benefit>false</benefit>
                    <data-elements>
                        <data-element id="rate5">
                            <reportable>false</reportable>
                            <comment/>
                        </data-element>
                        <data-element id="rate6">
                            <reportable>false</reportable>
                            <comment/>
                        </data-element>
                        <data-element id="rate7">
                            <reportable>false</reportable>
                            <comment/>
                        </data-element>
                        <data-element id="rate8">
                            <reportable>false</reportable>
                            <comment/>
                        </data-element>
                    </data-elements>
                </measure>
            </measures>
        </audit>
    </component>
</submission>

I'm trying to access the attributes with XPath selectors using a XMLMAP like this:

<?xml version="1.0" ?>
<SXLEMAP version="1.2">
  <TABLE name="AUDIT">  
    <TABLE-PATH syntax="XPath">  
       /submission/component/audit/measures/measure
     </TABLE-PATH>

    <COLUMN name="MEASURE" retain="YES">  
      <PATH syntax="XPath">  
         /submission/component/audit/measures/measure@id
        </PATH>
        <TYPE>character</TYPE>
        <DATATYPE>STRING</DATATYPE>
        <LENGTH>30</LENGTH>
     </COLUMN>

    <COLUMN name="RATES">  
      <PATH syntax="XPath">  
       //submission/component/audit/measures/measure/data-elements/data-element/@id
        </PATH>
        <TYPE>character</TYPE>
        <DATATYPE>STRING</DATATYPE>
        <LENGTH>20</LENGTH>
     </COLUMN>

    <COLUMN name="REPORT">  
      <PATH syntax="XPath">  
       /submission/component/audit/measures/measure/data-elements/data-element/reportable
        </PATH>
        <TYPE>character</TYPE>
        <DATATYPE>STRING</DATATYPE>
        <LENGTH>20</LENGTH>
     </COLUMN>

My output looks like:

   MEASURE                           RATES                   REPORT

   xyz                               rate4                   false
   abc                               rate8                   false

I want my output to get ALL the rates, not just the last rate, like:

   MEASURE                           RATES                   REPORT

   xyz                               rate1                   false
   xyz                               rate2                   false
   xyz                               rate3                   false
   xyz                               rate4                   false
   abc                               rate5                   false
   abc                               rate6                   false
   abc                               rate7                   false
   abc                               rate8                   false

Is this possible using XMLMAP or do I need something else?

Thanks in advance for your input!

****edit***********************************************;

Here is a basic SAS program that pulls the xml in and prints the output:

* set destination for output *;
LIBNAME DATA '<filepath>';

* set location of xml document and xml_map *;
LIBNAME XFILE XML '<filepath>\stack_example.xml' 
          XMLMAP='<filepath>\stack_import_map.xml';


* check import *;
PROC PRINT DATA= XFILE.AUDIT;
RUN;
  • Forgot to mention I found the following - but none helped me: http://stackoverflow.com/questions/1457638/xpath-get-nodes-where-child-node-contains-an-attribute ---- https://stackoverflow.com/questions/33096435/xpath-selecting-multiple-nodes ---- https://stackoverflow.com/questions/26320082/how-to-select-multiple-nodes-from-xml-with-xpath – xxsoundgirlxx Oct 15 '15 at 18:04
  • You're using SAS to import this via an xmlmap? What version of SAS? – Joe Oct 15 '15 at 18:51
  • Yes! I'm using SAS 9.2. – xxsoundgirlxx Oct 15 '15 at 19:45

1 Answers1

3

I figured it out...

In my table path I need to get down to the line level where I want a new observation (row) to start, like:

<TABLE name="AUDIT">  
        <TABLE-PATH syntax="XPath">  
           /submission/component/audit/measures/measure/data-elements/data-element
         </TABLE-PATH>

This will now select all the data-elements I want.