- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have found few papers on how to read an xml file with the help of an XSD file in order to produce a SAS dataset.
The task, I am ask for is the opposite.
So we start by reading a SAS dataset, then convert this dataset into an xml file with the help of an XSD file (XML Schema definition) to make sure that the obtained xml file respect the expected structure. I am using SAS EG 7.11
I am not sure that XML mapper can be used to carry out this task.
Does anyone have already done this task and if so how?
Regards,
ALP
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's an example that shows exporting XML to a data set and creating an XSD:
Exporting an XML Document with Separate Metadata
Unfortunately, that creates the XSD, doesn't use an existing XSD as an output schema. I think the only way to work this is the method you already discovered: import the XSD into XML Mapper to create an XML map, then export using the map as the structure.
You would need to install XML Mapper. It's part of SAS Base, but I think you'll have to install from your software depot -- it's not a separate download.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In SAS 9.4 you can use the XMLSCHEMA= option to reference an XSD, documented in the User's Guide.
Also, see this paper from @chrisschacherer: The SAS Programmer's Guide to XML and Web Services
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Chris,
I have already read your paper and what I have understood is that we can use XML Mapper and an XSD file to convert an XML file into a dataset.
What I am Interested in is the opposite situation: Use the information provided from a XML Schema Definition file as well as the one from a SAS Dataset to produce an XML file with the structure corresponding to the information provided into the XSD.
Can we do that in SAS EG 7.11 and if so How.
As I am not familiar at all with the XML file , could you please provide me a short example? Do I need Absolutely the XML Mapper Add-on
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have already try this code below. What I have understood, is that it take the SAS dataset and generate two files:
a) the XML file
b) the corresponding xsd FILE.
It is not what I would like to do.
The SAS data set and the XSD file are provided.
I want to use those information to write an XML file in compliance with the XSD provided file.
Again, based on your expertise, it is possible to do that and if so How.
Regards,
filename myxsd 'C:\Output\snacks.xsd'; /*1*/
libname output xmlv2 'C:\Output\snacks.xml'
xmlmeta=schemadata xmlschema=myxsd; /*2*/
data output.snacks; /*3*/
set sashelp.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Did you have a chance to look to my last post?
I Still need help...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's an example that shows exporting XML to a data set and creating an XSD:
Exporting an XML Document with Separate Metadata
Unfortunately, that creates the XSD, doesn't use an existing XSD as an output schema. I think the only way to work this is the method you already discovered: import the XSD into XML Mapper to create an XML map, then export using the map as the structure.
You would need to install XML Mapper. It's part of SAS Base, but I think you'll have to install from your software depot -- it's not a separate download.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Chris,
At the beginning, I though that my approach was the gone one but after some discussions with my team members, the objectives are clearer.
An XML Schema Definition file is written where some criteria regarding the table to be evaluated (SAS table or XML File) must met .
For example, imagine in Table A (provided by another service), variable sex, obs=122 is missing. IF the fact that this observation is missing in not critical based on the criteria of the XSD file the we accept the dataset otherwise an error report must be written who contains all the information for the observation # 122.
Same thing imagine in this Table A, based on the XSD file that var10 should be numeric and contains 9 number like a phone number, and for some reason we don't know, observation 425, contains only 6 number. Then this observation should be added to the error report with observation 122, and so on.
At the end, if the sas table is error free based on the XSD file, then we go to the next step the transformation to the XML type.
Otherwise, a sas table is provided containing all the observations (complete line) who contains errors.
I hope with those clarifications you will be able to direct me toward a nice solution.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It sounds like the XSD is not really a schema, but a set of business/validation rules. Is that right? And you need to have SAS code that "accepts" field values based on the rules/integrity constraints defined in this XSD?
I don't think the XML engine will help with the validation. I'm sure it would be possible to read the XSD and generate the rules in DATA step, but depending on how many variations of rules you have, it could be a lot of work.