471,350 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Can an XmlDocument file be created from an XSD file?

I'm not an expert on XML so have a question I have been unable to find an
answer. I have a fairly complex XSD file that was provided to me, for which
I used XSD.exe to generate a class. I added both the class and xsd files to
a C# VS 2005 project (Not Web Site). I need to create an XmlDocument that
will be populated with values and passed to a Web Service, where additional
elements will be populated and returned. I am at a complete loss as to how
to create the document from the class or xsd file.

For example, I tried the following:

LXML lxml = new LXML(); // NOTE: LXML is the class genererated from the
XSD file
XmlDocument doc = new XmlDocument();
doc.LoadXml(lxml.ToString());

It compiles, but chokes at runtime... looking nothing like an XML document.

Anyone know how this can be done... or IF it can be done?
Jan 25 '06 #1
3 1172
Ray,

Well, are you asking if you want an instance of XML that corresponds to
the schema, or can you take the schema and put it into an XML document? If
the answer is the latter, then you can load the schema as an XML document,
since XML Schemas ARE XML.

However, if you are looking to create an instance of the schema, that is
kind of hard. That's like saying give me an int (in .NET terms). You could
give them any value that falls in an int, but what value do you want?

Also, given that XML Schemas allow for elements of any type (i.e. no
constraints), then what do you possibly do there?

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ray Stevens" <nf*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm not an expert on XML so have a question I have been unable to find an
answer. I have a fairly complex XSD file that was provided to me, for
which I used XSD.exe to generate a class. I added both the class and xsd
files to a C# VS 2005 project (Not Web Site). I need to create an
XmlDocument that will be populated with values and passed to a Web
Service, where additional elements will be populated and returned. I am at
a complete loss as to how to create the document from the class or xsd
file.

For example, I tried the following:

LXML lxml = new LXML(); // NOTE: LXML is the class genererated from the
XSD file
XmlDocument doc = new XmlDocument();
doc.LoadXml(lxml.ToString());

It compiles, but chokes at runtime... looking nothing like an XML
document.

Anyone know how this can be done... or IF it can be done?

Jan 25 '06 #2

"Ray Stevens" <nf*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
....
For example, I tried the following:

LXML lxml = new LXML(); // NOTE: LXML is the class genererated from the XSD file
XmlDocument doc = new XmlDocument();
doc.LoadXml(lxml.ToString());

It compiles, but chokes at runtime... looking nothing like an XML

document.
....

You have to use XmlSerializer class to serialize it to XML. ToString() does
not return xml string (it might if you override it, but it is not doing it
by default).

Regards,
Goran


Jan 25 '06 #3

"Ray Stevens" <nf*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm not an expert on XML so have a question I have been unable to find an
answer. I have a fairly complex XSD file that was provided to me, for
which I used XSD.exe to generate a class. I added both the class and xsd
files to a C# VS 2005 project (Not Web Site). I need to create an
XmlDocument that will be populated with values and passed to a Web
Service, where additional elements will be populated and returned. I am at
a complete loss as to how to create the document from the class or xsd
file.

For example, I tried the following:

LXML lxml = new LXML(); // NOTE: LXML is the class genererated from the
XSD file
XmlDocument doc = new XmlDocument();
doc.LoadXml(lxml.ToString());

It compiles, but chokes at runtime... looking nothing like an XML
document.

Anyone know how this can be done... or IF it can be done?


See XmlSerializer - it will serialize/deserialize the object lxml as a
stream of characters ("<xml .....").

XmlSerializer can serialize pretty well anything as XML.
The purpose of xsd.exe is to put all the right attributes and stuff in LXML
to make XmlSerializer serialize it in the form specified by the XSD file.

You do not need XmlDocument at all.
Jan 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tom Pearson | last post: by
1 post views Thread by Martin Honnen | last post: by
3 posts views Thread by Mungo Jerrie | last post: by
2 posts views Thread by Throne Software | last post: by
2 posts views Thread by Ryo | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.