Help using Base SAS procedures

Pulling out tag info from xml file

Reply
Super Contributor
Posts: 398

Pulling out tag info from xml file

I have an xml file that was sent to me from an outside source.  What I need to do it parse it so I have all the tag and property info put into a table.

I have tried importing it as an xml file but the file isn't formatted correctly.  I have no say in how the file comes to me so I decided to import the file and pull the info out myself.

This is just a small example of some of the stuff within the file.

<prj name="Test Prj">

<Level1 name="L101B">

<codes val="1" label="Temp 1" />

<codes val="2" label="Temp 2" />

<codes val="3" label="Temp 3" />

.

.

.

</prj>

Some tags have up to 9 properties so I know a loop will do it but I can't figure out how to grab each lines of info.

Example output Table

Tag      Property1  Value1       Property2 Value2  ...

prj        name        "Test Prj"  

Level1  name         "L101B"

codes  val              "1"           label         "Temp 1"

codes  val              "2"           label         "Temp 2"

codes  val              "3"           label          "Temp 3"

Thank you for your help

SAS Super FREQ
Posts: 8,743

Re: Pulling out tag info from xml file


Hi:

  The XML Libname engine only works "out of the box" with very regular, non-hierarchical XML. Did you try turning your XML into a SAS dataset using the XML Mapper to map from XML "irregular" form to a SAS dataset?

  That might be worth a try. There is doc on how to use the XML Mapper and if you really get stumped, Tech Support can help. I'd try that road first before you parse this yourself.

  Why do you need to save the "container" tags like <prj> and <Level1>? It looks to me like the output structure would be a dataset with the name L101B and then it would have

code label

1    Temp1

2     Temp2

3    Temp3

or else the DATASET would be named PRJ and there would be a variable named L101B in the dataset. In any case, if you created a long and skinny dataset, then you could transpose it quite easily.

  Just a thought for an alternative approach.

cynthia

Super Contributor
Posts: 398

Re: Pulling out tag info from xml file

Hi Cynthia,

Thank you so much for your reply.    I have to do this process in a sas program so I can't use the XML mapper.

What i'm trying to do is store this data in a sas dataset.

I have to have the output like the example I posted.  There is another process that takes this data set and uploads the data to a different database.

I don't think the scan function is going to work for my situation.  There are some that have label="""TEMP 1""" and i'm not sure how to parse that out.

Any other help you can give me would be appreciated.  I want to eventually make it a macro.

Thank you

SAS Super FREQ
Posts: 8,743

Re: Pulling out tag info from xml file

Well, you only build the XML map 1 time. Then, you could use it over and over. So the XML map is just a one-time step. but I'll have to think about it.....basically, you just want to strip out the tags???

Will there only be 1 Level tag? Or can you have multiple Level 1 tags???? Can you show an example of a tag that has 9 properties? Is it a code tag???

cynthia

Super Contributor
Posts: 398

Re: Pulling out tag info from xml file

Hi Cynthia,

Thank you for your reply.  The issue has been resolved.  The data that was orginally sent to me was incorrect and they are working on correcting it and sending it in a different format.

Thank you once again for all your help

Ask a Question
Discussion stats
  • 4 replies
  • 279 views
  • 0 likes
  • 2 in conversation