libname xml92: change the root element

Reply
Occasional Contributor
Posts: 5

libname xml92: change the root element

Dear all,

 

I work with SAS 9.3 and I manage to create an xml with xml92 with the following commands:

 

libname DATAXML xml92 "&path.\FE_RSC_ECL_EV.xml" tagset=tagsets.sasxmiss ;

data  DATAXML.FILE; set DATASAS.FILE; run;

 

The root element is <TABLE>. This is a convention SAS uses when writing out XML files using the XML libname engine.

 

Is anybody would know how to change "TABLE"?

I thought I could use "proc template" and create a tagset template but I think that I have to recode all of the structure...

 

In advance thank you to all those who will try to help me.

 

Céline

 

 

Super User
Super User
Posts: 7,721

Re: libname xml92: change the root element

Hi,

 

Can't actually find that tagset in my install, maybe its another product.  Anyways, if you open the tagset, its is just a proc template.  You could copy all the text over, rename it, and create your own tagset, changing that element.  

Me, I tend to stick with just a simple datastep with a file, and write each bit out:

data _null_;
  set sashelp.cars (keep=make model type) end=last;
  file "s:\temp\rob\cars.xml";
  if _n_=1 then do;
    put '<?xml version="1.0" encoding="UTF-8"?>';
    put "<cars>";
  end;
  put "  <record>";
  put "    <make>" make "</make>";
  put "    <model>" model "</model>";
  put "    <type>" type "</type>";
  put "  </record>";
  if last then put "</cars>";
run;
Occasional Contributor
Posts: 5

Re: libname xml92: change the root element

Thank you for your answer.

 

Actually, we have a lot of tables to export in the xml file, so we don't want to code all the variables of all the tables. Even if we can automate the code...

Super User
Super User
Posts: 7,721

Re: libname xml92: change the root element

Ah, that's a shame as you could automate it:

data xml (keep=libname memname name xml_out);
  set sashelp.vcolumn (where=(libname="SASHELP" and memname in ("CARS","CLASS"))) end=last; 
  length xml_out $2000;
  by memname;
  if _n_=1 then do;
    xml_out='data _null_; set '||strip(libname)||'.'||strip(memname)||' end=last; file "s:\temp\rob\out.xml";'; output;
    xml_out='if _n_=1 then put '||"'"||'<?xml version="1.0" encoding="UTF-8"?>'||"'"||';'; output;
    xml_out='if _n_=1 then put "<root_node>";'; output; 
  end;
  if first.memname then do;
    if _n_ > 1 then do;
      xml_out='; run; data _null_; set '||strip(libname)||'.'||strip(memname)||' end=last; file "s:\temp\rob\out.xml" mod;'; output;
    end;
    xml_out='if _n_=1 then put "<'||strip(memname)||'>";'; output;
    xml_out='put "  <record>";'; output;
  end;
  xml_out='put "    <'||strip(name)||'>" '||strip(name)||' "</'||strip(name)||'>";'; output; 
  if last.memname then do;
    xml_out='put "  </record>";'; output;
    xml_out='if last then put "</'||strip(memname)||'>";'; output;
  end;
  if last then do;
    xml_out='if last then put "</root_node>"; run;'; output;
  end;
run;

data _null_;
  set xml;
  call execute(xml_out);
run;
Ask a Question
Discussion stats
  • 3 replies
  • 260 views
  • 2 likes
  • 2 in conversation