Help using Base SAS procedures

XMLNS attribute in table name causes XML Engine Libname to return dataset with no observations

Reply

XMLNS attribute in table name causes XML Engine Libname to return dataset with no observations

I'm trying to read in an XML using an XML map that was provided to me (supposed to work with the associated XML files), but it seems that the xmlns attribute in my table element causes the XML engine libname statement to return a dataset with no observations.

Below is a slightly modified copy of the NHL XML file, the associated map and statements that are included as an example in the following link : SAS(R) 9.2 XML LIBNAME Engine: User's Guide, Second Edition

The only difference is the addition of the xmlns="ExtractionSchema" attribute in the NHL tag (highlighted red). Without the tag, the observations read in just fine, but with it, no observations are returned. Also, interestingly, if the xmlns attribute is replaced with another attribute (for example, height="850"), the observations are read in just fine. What would need to be changed in the XML map to fix the problem since I can't remove the xmlns attribute?

Thanks in advance for any help!

XML:

<?xml version="1.0" encoding="iso-8859-1" ?>

<NHL xmlns="ExtractionSchema">

  <CONFERENCE> Eastern

    <DIVISION> Southeast

      <TEAM name="Thrashers"  abbrev="ATL" />

      <TEAM name="Hurricanes" abbrev="CAR" />

      <TEAM name="Panthers"   abbrev="FLA" />

      <TEAM name="Lightning"  abbrev="TB" />

      <TEAM name="Capitals"   abbrev="WSH" />

   </DIVISION>

</CONFERENCE>

<CONFERENCE> Western

   <DIVISION> Pacific

     <TEAM name="Stars"   abbrev="DAL" />

     <TEAM name="Kings"   abbrev="LA" />

     <TEAM name="Ducks"   abbrev="ANA" />

     <TEAM name="Coyotes" abbrev="PHX" />

     <TEAM name="Sharks"  abbrev="SJ" />

   </DIVISION>

  </CONFERENCE>

</NHL>

XML Map:

<?xml version="1.0" ?>

<SXLEMAP version="1.2">

  <TABLE name="TEAMS">

        <TABLE-PATH syntax="XPATH">

           /NHL/CONFERENCE/DIVISION/TEAM

         </TABLE-PATH>

        <COLUMN name="NAME">

          <PATH>

             /NHL/CONFERENCE/DIVISION/TEAM@name

            </PATH>

            <TYPE>character</TYPE>

            <DATATYPE>STRING</DATATYPE>

            <LENGTH>30</LENGTH>

         </COLUMN>

        <COLUMN name="ABBREV">

          <PATH>

           /NHL/CONFERENCE/DIVISION/TEAM/@abbrev

            </PATH>

            <TYPE>character</TYPE>

            <DATATYPE>STRING</DATATYPE>

            <LENGTH>3</LENGTH>

         </COLUMN>

       <COLUMN name="CONFERENCE" retain="YES">

          <PATH>/NHL/CONFERENCE</PATH>

            <TYPE>character</TYPE>

            <DATATYPE>STRING</DATATYPE>

            <LENGTH>10</LENGTH>

        </COLUMN>

       <COLUMN name="DIVISION" retain="YES">

           <PATH>

              /NHL/CONFERENCE/DIVISION

            </PATH>

            <TYPE>character</TYPE>

            <DATATYPE>STRING</DATATYPE>

            <LENGTH>10</LENGTH>

        </COLUMN>

  </TABLE>

</SXLEMAP>

Statements to run:

filename NHL 'C:\My Documents\XML\NHL.xml';

filename MAP 'C:\My Documents\XML\NHL.map';

libname NHL xml xmlmap=MAP;

proc print data=NHL.TEAMS;

run;

SAS Super FREQ
Posts: 8,743

Re: XMLNS attribute in table name causes XML Engine Libname to return dataset with no observations

Hi:

  It was my understanding that the XMLNS (as shown on this web site XML Namespaces ) was supposed to be a URI -- so by this definition of a URI scheme URI scheme - Wikipedia, the free encyclopedia the XMLNS you have is not a URI. So I am not sure that there is a way to "skip" over it in an XML Map. That would be a question for Tech Support..

  I feel that your XMLNS attribute is not formed correctly, from the W3C web site, it looks like the XMLNS should be XMLNS:xxx="some-URI" and your XMLNS is missing the : and the xxx piece. I wonder if you  changed the XMLNS to be something like XMLNS:xxx whether the XML would read correctly using your MAP. At least, that would indicate that the folks who are sending you the XML file need to revisit the XMLNS attribute that they are sending. But again, for more specific help, you need Tech Support, in my opinion.

cynthia


xmlns_on_root_tag.pngxmlns_on_element_tag.png
Super User
Super User
Posts: 6,500

Re: XMLNS attribute in table name causes XML Engine Libname to return dataset with no observations

Are you sure you don't have OBS=0 set?

Your example works for me on SAS 9.2 and 9.4.

NOTE: Copyright (c) 2002-2008 by SAS Institute Inc., Cary, NC, USA.

NOTE: SAS (r) Proprietary Software 9.2 (TS2M3)

filename NHL temp ; *'C:\My Documents\XML\NHL.xml';

filename MAP temp ; *'C:\My Documents\XML\NHL.map';

data _null_; file nhl; input; put _infile_;

cards4;

<?xml version="1.0" encoding="iso-8859-1" ?>

<NHL xmlns="ExtractionSchema">

  <CONFERENCE> Eastern

    <DIVISION> Southeast

      <TEAM name="Thrashers"  abbrev="ATL" />

      <TEAM name="Hurricanes" abbrev="CAR" />

      <TEAM name="Panthers"   abbrev="FLA" />

      <TEAM name="Lightning"  abbrev="TB" />

      <TEAM name="Capitals"   abbrev="WSH" />

   </DIVISION>

</CONFERENCE>

<CONFERENCE> Western

   <DIVISION> Pacific

     <TEAM name="Stars"   abbrev="DAL" />

     <TEAM name="Kings"   abbrev="LA" />

     <TEAM name="Ducks"   abbrev="ANA" />

     <TEAM name="Coyotes" abbrev="PHX" />

     <TEAM name="Sharks"  abbrev="SJ" />

   </DIVISION>

  </CONFERENCE>

</NHL>

;;;;

data _null_; file map; input; put _infile_;

cards4;

<?xml version="1.0" ?>

<SXLEMAP version="1.2">

  <TABLE name="TEAMS">

        <TABLE-PATH syntax="XPATH">

           /NHL/CONFERENCE/DIVISION/TEAM

         </TABLE-PATH>

        <COLUMN name="NAME">

          <PATH>

             /NHL/CONFERENCE/DIVISION/TEAM@name

            </PATH>

            <TYPE>character</TYPE>

<DATATYPE>STRING</DATATYPE>

            <LENGTH>30</LENGTH>

         </COLUMN>

        <COLUMN name="ABBREV">

          <PATH>

/NHL/CONFERENCE/DIVISION/TEAM/@abbrev

            </PATH>

            <TYPE>character</TYPE>

<DATATYPE>STRING</DATATYPE>

            <LENGTH>3</LENGTH>

         </COLUMN>

       <COLUMN name="CONFERENCE" retain="YES">

<PATH>/NHL/CONFERENCE</PATH>

            <TYPE>character</TYPE>

<DATATYPE>STRING</DATATYPE>

            <LENGTH>10</LENGTH>

        </COLUMN>

       <COLUMN name="DIVISION" retain="YES">

           <PATH>

              /NHL/CONFERENCE/DIVISION

            </PATH>

            <TYPE>character</TYPE>

<DATATYPE>STRING</DATATYPE>

            <LENGTH>10</LENGTH>

        </COLUMN>

  </TABLE>

</SXLEMAP>

;;;;

libname NHL xml xmlmap=MAP;

proc print data= nhl.teams;

run;

Valued Guide
Posts: 3,208

Re: XMLNS attribute in table name causes XML Engine Libname to return dataset with no observations

Same with me, the given example works with UE with no issues.
Cytnhia is right with her remark on the xmlns tag SAS(R) 9.4 XML LIBNAME Engine: User's Guide   (Including Namespace Elements in an XMLMap)
A nice more understandable document on namespaces is http://www.pharmasug.org/proceedings/2014/BB/PharmaSUG-2014-BB11.pdf

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 3 replies
  • 398 views
  • 0 likes
  • 4 in conversation