473,395 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1217
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom Pearson | last post by:
I have created an XmlDocument and can see that this is correctly formed and has a root element If I Save the doc to a file and reload it all works o If I dump the doc to a stream, again using the...
1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
4
by: Carl Williams | last post by:
Hope someone can help with this... I have looked at all the newsgroup articles and put into practice all the suggestions but to no good. I am pretty new to CSharp and .Net so any help would be...
1
by: David | last post by:
I need to find a good online resource which teaches the use of the XmlDocument framework in more depth than is covered in MS's online doc. I need to create a multi-level XML document like the one...
3
by: Mungo Jerrie | last post by:
Hi there :-) I have some problems with the same instance of my xmldocument across 3 different classes. See code below: class one { protected static XmlDocument doc = new XmlDocument(); ...
2
by: Throne Software | last post by:
I am working on a ASP .Net page with a C# back end that displays, and give the option to save, an XmlDocument object. While displaying the XML in a literal was easy, I can't figure out how to allow...
2
by: Ryo | last post by:
Hello ! I have an XmlDocument in memory and I want to put this document as datasource of my treeview. How to do this ? Thanks.
2
by: feng | last post by:
I think I didn't phrase my quetion clear enough in the last post. Here is what I need: In my VB.Net code, I already have a XML created in XMLDocument formate. I can also convert it into a string...
0
by: rawatgaurav81 | last post by:
I had this strange problem in handling XMLDocuments in asp.net.Though the problem occurs while working on the main application.I will try to explain it with shorter code. I had a form with 2...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.