xpath:从xml

时间:2015-10-15 17:59:11

标签: xml xpath sas

无法获得所需的输出......也许它不可能,但我是XPath选择器的新手。

我有XML:

<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>

我试图使用像这样的XMLMAP使用XPath选择器访问属性:

<?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>

我的输出如下:

   MEASURE                           RATES                   REPORT

   xyz                               rate4                   false
   abc                               rate8                   false

我希望我的输出获得所有费率,而不仅仅是最后一个费率,例如:

   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

这可能使用XMLMAP还是需要其他东西?

提前感谢您的意见!

****编辑****************************************** *****;

这是一个基本的SAS程序,它将xml拉入并打印输出:

* 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;

1 个答案:

答案 0 :(得分:3)

我明白了......

在我的表格路径中,我需要深入到我希望开始新观察(行)的行级别,例如:

studentDict

现在将选择我想要的所有数据元素。