BookmarkSubscribeRSS Feed
FundamentalNatureOfTime
Calcite | Level 5

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;

3 REPLIES 3
Cynthia_sas
SAS Super FREQ

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
Tom
Super User Tom
Super User

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;

jakarman
Barite | Level 11

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1540 views
  • 0 likes
  • 4 in conversation