Load XML file into object. Best method? - xsd

We are receiving an XML file from our client. I want to load the data from this file into a class, but am unsure about which way to go about it.
I have an XSD to defining what is expected in the XML file, so therefore i can easily validate the XML file.
Can i use the XSD file to load the data into a POCO, using some sort of serialization?
The other way i was thinking was to load the xml into a XMLDocument and use XPath to populate each property in my class.
Cheers for any advice

Depending on how complex the XSD is, you have a couple of options:
Use xsd.exe to generate C# classes which can be used in conjunction with the XmlSerializer.
Use svcutil.exe with the /dconly argument to generate DataContract-attributed types appropriate for use with the DataContractSerializer.

Related

Generate DDIC structure from XSD?

I have a number of XSDs that are part of the enterprise definitions for several services at the client.
I would like to be able to take a single XSD and generate a DDIC structure from it (without the use of PI!)
Seeing as you can generate proxies directly from a WSDL, and this also generates structures and data elements from the XSD definitions inside the WSDL, there is obviously already ABAP code that does this.
But do you know what classes/function modules to use to achieve this? Perhaps there is a convenient utility function or class method that takes the XSD as input and generates the relevant DDIC objects?
Some background on why I need this:
Some of the services include variable sections that include a piece of XML containing the data for one of the enterprise XSD entities; I am hoping to have a DDIC representation of these, which I can fill at runtime and then convert to XML to include in the message.
There is a program on the system called SPROX_XSD2PROXY with which you can upload one or more XSD files which will generate proxy objects for you.
You also end up with a service consumer with a corresponding class and what looks like a dummy operation.
The program is fairly short; it uploads the files(s) to an XSTRING, then converts the XSD(s) to WSDL(s) and finally the WSDL(s) to proxy objects using methods of a class called CL_PROXY_TEST_UTILS.
However, the result is satisfactory as it does give me a structure I can work with. And by examining the contents of those methods, it may be possible to build a more fine-tuned tool if I need one.

Consuming .ashx files in C#

I need to consume / parse .ashx files in C#. I could create strongly typed C# class by using xsd.exe and add this to my project. But the schema of the .ashx could change at anytime.
So, I don't want to create C# classes using command line utility like xsd.
Is there any way i can create C# class on the fly from a .ashx and use the class to parse the .ashx content?.
I assume that what you need to parse/consume is the XML produced by the .ashx handler.
There is no way I know of to generate a class directly using .NET functions - you could call xsd.exe and then load and compile the generated code - quite a hack.

XSD TO XML Conversion

I want to write a java program, Input - XSD File I need to retreive all the element name from the xsd and need to create an xml file as an output with the retreived element name. If anyone of you have the sample code, please share it.
Thanks
You are not rephrasing your question,but still i found some suggestions for you.See if its useful for you.Please check the following link...
http://www.narendranaidu.com/2010/04/xsd-to-xml-and-vice-versa.html
Alright use JAXME or XSOM to parse your schema and use DOM or JDOM to write the element names to new xml
if you want to create a sample XML from schema ..you can use XMLspear tool to do that.
http://www.donkeydevelopment.com/

Include the file name of the xsd schema I am processing with xslt

Hello
I am generating Objective-C class files with Saxon via XSLT and in a comment header would like to include information as to which xsd was used for their creation. Is there any way I can access the current filename during an xslt transformation?
Would be great if anyone had an idea...thanks!
Assuming XSLT/XPath 2.0 or later you can use document-uri(/) http://www.w3.org/TR/xpath-functions/#func-document-uri to find the URI of the input document and if you only want the file name then you could use tokenize(document-uri(/), '/')[last()].

Split large xsd into one file per type

Is ther a way to split a large XSD file with multiple type definitions into one file per type?
Use xs:include.
If you want to automitize the process, consider using XSLT. XML Schema is XML after all.

Resources