BookmarkSubscribeRSS Feed
ThierryHerrie
Obsidian | Level 7

Hi,

 

I'm creating a XML file using the XMLV2 library engine. The code looks like this:

FILENAME MyXML "&dir.\kip.xml" ;
LIBNAME MyXML XMLV2 XMLENCODING=utf8 ;

DATA MyXML.Klas ;
  SET sashelp.class (OBS=1) ;
RUN ;

LIBNAME MyXML CLEAR ;
FILENAME MyXML CLEAR ;

It successfully creates a XML file. However I would like to change 2 things. If you look at the XML file 

<?xml version="1.0" encoding="utf-8" ?>
<TABLE>
   <KLAS>
      <Name>Alfred</Name>
      <Sex>M</Sex>
      <Age>14</Age>
      <Height>69</Height>
      <Weight>112.5</Weight>
   </KLAS>
</TABLE>

I would like to change the root tag to Klassen and the upcase KLAS to Klas. So it looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<Klassen>
   <Klas>
      <Name>Alfred</Name>
      <Sex>M</Sex>
      <Age>14</Age>
      <Height>69</Height>
      <Weight>112.5</Weight>
   </Klas>
</Klassen>

Is there any way to do this?

 

Thierry

2 REPLIES 2
Tom
Super User Tom
Super User

You probably will need to create a map file.

https://documentation.sas.com/?docsetId=engxml&docsetTarget=p030dni55gms3qn1xxc7xxpzn06p.htm&docsetV...

 

Or you could just post-process the file.

data _null_;
  infile  "&dir.\kip.xml" ;
  file  "&dir.\kip_fixed.xml" ;
  input ;
  if _infile_ = '<TABLE>' then _infile_='<Klassen>';
  else if _infile_ = '</TABLE>' then _infile_='</Klassen>';
  else if left(_infile_)='<KLAS>' then _infile_='<Klas>';
  else if left(_infile_)='</KLAS>' then _infile_='</Klas>';
  put _infile_;
run;
ThierryHerrie
Obsidian | Level 7

Postprocessing the file was my plan B Smiley Happy

Think I will just do that, thanks!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 412 views
  • 0 likes
  • 2 in conversation