473,549 Members | 2,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you use a XSD to create a XML document?

Is it possible to load a XSD and loop throw the nodes and attributes that
you whant filled out, and then generate a XML instance with the trees and
data that you have filled data in?
And how do you do that?

Regards Paw
Nov 12 '05 #1
5 17647
what do you *really* want to do?

do you want a generic xsd-to-xml generator? Something that can contrive XML
documents from any general XSD?
or is there a particular XSD you want to generate for?

one approach I have used is to use "xsd.exe /c" to generate classes, then
just instantiate the classes. Serialization of an instance of said class
produces an XML document that conforms to the XSD. example:

http://www.winisp.net/cheeso/srcview...ile=Xsd2xml.cs
However, xsd.exe supports only a subset of W3C XML Schema. For example,
lists (as elements) are not well supported.

-Dino
"Paw Pedersen" <ne**@paws.dk > wrote in message
news:Op******** ******@TK2MSFTN GP11.phx.gbl...
Is it possible to load a XSD and loop throw the nodes and attributes that
you whant filled out, and then generate a XML instance with the trees and
data that you have filled data in?
And how do you do that?

Regards Paw

Nov 12 '05 #2
What I really whant, is the following:
I receive a xml instance and load it into XmlDocument. I have a XSD
specifying the full XML for the xml instance I have received. I now want to
iterate throw the xsd tree with a foreach-node/foreach-attribut the same way
as I can do it with my XmlDocument instance. I need this because I need to
do some comparison with the xml instance and the xsd and maybe fill in some
"blank" values in the xml instance (not just a simple validate againt XSD).
The XSD can be severel different XSD's and therefore I can't use the
"xsd.exe /c".
Hope you have a good idea on how to do this. I don't know much about working
with XSD in .Net.

Regards Paw

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:#$******** ******@TK2MSFTN GP12.phx.gbl...
what do you *really* want to do?

do you want a generic xsd-to-xml generator? Something that can contrive XML documents from any general XSD?
or is there a particular XSD you want to generate for?

one approach I have used is to use "xsd.exe /c" to generate classes, then
just instantiate the classes. Serialization of an instance of said class
produces an XML document that conforms to the XSD. example:

http://www.winisp.net/cheeso/srcview...ile=Xsd2xml.cs

However, xsd.exe supports only a subset of W3C XML Schema. For example,
lists (as elements) are not well supported.

-Dino
"Paw Pedersen" <ne**@paws.dk > wrote in message
news:Op******** ******@TK2MSFTN GP11.phx.gbl...
Is it possible to load a XSD and loop throw the nodes and attributes that you whant filled out, and then generate a XML instance with the trees and data that you have filled data in?
And how do you do that?

Regards Paw


Nov 12 '05 #3
Read in the Schema and walk through it. One way to do it: build a map in
memory of required and optional fields, and then walk the XML DOM to
determine which elements are present or not present. It sounds messy and
tedious.

see this for a hint:
http://www.fawcette.com/xmlmag/2002_...hlin_09_03_02/
The XSD can be severel different XSD's and therefore I can't use the
"xsd.exe /c".
The possible use of multiple XSDs does not prevent you from using xsd.exe.
For example, you could have 3 or 4 (or more) sets of classes derived from 3
or 4 (or more) XSDs. Then you get can object programming semantics rather
than XML parsing.

Example, you de-serialize the XML file into an instance of Class1, then
examine the fields in that instance of Class1 to see if they have been set.

// Class1 is generated from xsd.exe /c (From a given XSD)
XmlSerializer s= new XmlSerializer(t ypeof(Class1));
Class1 c= s.Deserialize(t hefile);
if (c.Field1==null ) c.Field1= Field1DefaultVa lue;
//etc

Actually, by modifying the generated source for Class1, you could insert
"default" values in the instances by modifying the default ctor. These
"default" values would be over-written when de-serialiing a document that
actually has values for them. Going with this approach, you wouldn't need
to

if (c.Field1==null ) c.Field1= Field1DefaultVa lue;
//etc

....because all that would be done implicitly. On the other hand if you have
more complex rules for which fields need to be set (eg, relationships
between one field and another), then this tweak may not work. but xml
serialization still may be a nice simplification.

Though I agree, XML serialization (and xsd.exe) does not work if there is an
*infinite* number of possible XSDs.

-D
"Paw Pedersen" <ne**@paws.dk > wrote in message
news:uF******** ******@TK2MSFTN GP15.phx.gbl... What I really whant, is the following:
I receive a xml instance and load it into XmlDocument. I have a XSD
specifying the full XML for the xml instance I have received. I now want
to
iterate throw the xsd tree with a foreach-node/foreach-attribut the same
way
as I can do it with my XmlDocument instance. I need this because I need to
do some comparison with the xml instance and the xsd and maybe fill in
some
"blank" values in the xml instance (not just a simple validate againt
XSD).
Hope you have a good idea on how to do this. I don't know much about
working
with XSD in .Net.

Regards Paw

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:#$******** ******@TK2MSFTN GP12.phx.gbl...
what do you *really* want to do?

do you want a generic xsd-to-xml generator? Something that can contrive

XML
documents from any general XSD?
or is there a particular XSD you want to generate for?

one approach I have used is to use "xsd.exe /c" to generate classes, then
just instantiate the classes. Serialization of an instance of said class
produces an XML document that conforms to the XSD. example:

http://www.winisp.net/cheeso/srcview...ile=Xsd2xml.cs


However, xsd.exe supports only a subset of W3C XML Schema. For example,
lists (as elements) are not well supported.

-Dino
"Paw Pedersen" <ne**@paws.dk > wrote in message
news:Op******** ******@TK2MSFTN GP11.phx.gbl...
> Is it possible to load a XSD and loop throw the nodes and attributes that > you whant filled out, and then generate a XML instance with the trees and > data that you have filled data in?
> And how do you do that?
>
> Regards Paw
>
>



Nov 12 '05 #4
Thanks for your input.
I need the class to be dynamical so it can load any XSD without privious
knowledge, and therefore I can't use the "xsd.exe /c".
Also the "default" values are dependent on the xml instance and therefor I
can't use the "default" values from the XSD.
Basically I loop throw the xml instance I have received, and for every node
with one or more attributes filled out, I need to check in the xsd if there
exist more attributes to this specific node, and if there does, I need to
fill them with a blank value in the xml instance.
I have found out how to load the XSD ind a XmlSchema class and I have the
xpath to the specific node, for which I need to check if it has any
attributes. I just don't know how to "navigate" throw a XmlSchem instance,
and get the list of attribute names this specific node has.
Any ideas?

Regards Paw

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:OG******** ******@TK2MSFTN GP09.phx.gbl...
Read in the Schema and walk through it. One way to do it: build a map in
memory of required and optional fields, and then walk the XML DOM to
determine which elements are present or not present. It sounds messy and
tedious.

see this for a hint:
http://www.fawcette.com/xmlmag/2002_...hlin_09_03_02/
The XSD can be severel different XSD's and therefore I can't use the
"xsd.exe /c".
The possible use of multiple XSDs does not prevent you from using xsd.exe.
For example, you could have 3 or 4 (or more) sets of classes derived from

3 or 4 (or more) XSDs. Then you get can object programming semantics rather than XML parsing.

Example, you de-serialize the XML file into an instance of Class1, then
examine the fields in that instance of Class1 to see if they have been set.
// Class1 is generated from xsd.exe /c (From a given XSD)
XmlSerializer s= new XmlSerializer(t ypeof(Class1));
Class1 c= s.Deserialize(t hefile);
if (c.Field1==null ) c.Field1= Field1DefaultVa lue;
//etc

Actually, by modifying the generated source for Class1, you could insert
"default" values in the instances by modifying the default ctor. These
"default" values would be over-written when de-serialiing a document that
actually has values for them. Going with this approach, you wouldn't need
to

if (c.Field1==null ) c.Field1= Field1DefaultVa lue;
//etc

...because all that would be done implicitly. On the other hand if you have more complex rules for which fields need to be set (eg, relationships
between one field and another), then this tweak may not work. but xml
serialization still may be a nice simplification.

Though I agree, XML serialization (and xsd.exe) does not work if there is an *infinite* number of possible XSDs.

-D
"Paw Pedersen" <ne**@paws.dk > wrote in message
news:uF******** ******@TK2MSFTN GP15.phx.gbl...
What I really whant, is the following:
I receive a xml instance and load it into XmlDocument. I have a XSD
specifying the full XML for the xml instance I have received. I now want
to
iterate throw the xsd tree with a foreach-node/foreach-attribut the same
way
as I can do it with my XmlDocument instance. I need this because I need to
do some comparison with the xml instance and the xsd and maybe fill in
some
"blank" values in the xml instance (not just a simple validate againt
XSD).
Hope you have a good idea on how to do this. I don't know much about
working
with XSD in .Net.

Regards Paw

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:#$******** ******@TK2MSFTN GP12.phx.gbl...
what do you *really* want to do?

do you want a generic xsd-to-xml generator? Something that can contrive
XML
documents from any general XSD?
or is there a particular XSD you want to generate for?

one approach I have used is to use "xsd.exe /c" to generate classes,

then just instantiate the classes. Serialization of an instance of said class produces an XML document that conforms to the XSD. example:

http://www.winisp.net/cheeso/srcview...ile=Xsd2xml.cs


However, xsd.exe supports only a subset of W3C XML Schema. For example, lists (as elements) are not well supported.

-Dino
"Paw Pedersen" <ne**@paws.dk > wrote in message
news:Op******** ******@TK2MSFTN GP11.phx.gbl...
> Is it possible to load a XSD and loop throw the nodes and attributes

that
> you whant filled out, and then generate a XML instance with the trees

and
> data that you have filled data in?
> And how do you do that?
>
> Regards Paw
>
>



Nov 12 '05 #5
I have reposted this question since it kind of a new subject :o)
Reposted with subject: "Get attributes from XmlSchema for specific Node
referenced by Xpath"

Regards Paw

"Paw Pedersen" <ne**@paws.dk > wrote in message
news:Ow******** ******@TK2MSFTN GP12.phx.gbl...
Thanks for your input.
I need the class to be dynamical so it can load any XSD without privious
knowledge, and therefore I can't use the "xsd.exe /c".
Also the "default" values are dependent on the xml instance and therefor I
can't use the "default" values from the XSD.
Basically I loop throw the xml instance I have received, and for every node with one or more attributes filled out, I need to check in the xsd if there exist more attributes to this specific node, and if there does, I need to
fill them with a blank value in the xml instance.
I have found out how to load the XSD ind a XmlSchema class and I have the
xpath to the specific node, for which I need to check if it has any
attributes. I just don't know how to "navigate" throw a XmlSchem instance,
and get the list of attribute names this specific node has.
Any ideas?

Regards Paw

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:OG******** ******@TK2MSFTN GP09.phx.gbl...
Read in the Schema and walk through it. One way to do it: build a map in
memory of required and optional fields, and then walk the XML DOM to
determine which elements are present or not present. It sounds messy and tedious.

see this for a hint:
http://www.fawcette.com/xmlmag/2002_...hlin_09_03_02/
The XSD can be severel different XSD's and therefore I can't use the
"xsd.exe /c".
The possible use of multiple XSDs does not prevent you from using xsd.exe. For example, you could have 3 or 4 (or more) sets of classes derived from 3
or 4 (or more) XSDs. Then you get can object programming semantics rather
than XML parsing.

Example, you de-serialize the XML file into an instance of Class1, then
examine the fields in that instance of Class1 to see if they have been

set.

// Class1 is generated from xsd.exe /c (From a given XSD)
XmlSerializer s= new XmlSerializer(t ypeof(Class1));
Class1 c= s.Deserialize(t hefile);
if (c.Field1==null ) c.Field1= Field1DefaultVa lue;
//etc

Actually, by modifying the generated source for Class1, you could insert
"default" values in the instances by modifying the default ctor. These
"default" values would be over-written when de-serialiing a document

that actually has values for them. Going with this approach, you wouldn't need to

if (c.Field1==null ) c.Field1= Field1DefaultVa lue;
//etc

...because all that would be done implicitly. On the other hand if you

have
more complex rules for which fields need to be set (eg, relationships
between one field and another), then this tweak may not work. but xml
serialization still may be a nice simplification.

Though I agree, XML serialization (and xsd.exe) does not work if there

is an
*infinite* number of possible XSDs.

-D
"Paw Pedersen" <ne**@paws.dk > wrote in message
news:uF******** ******@TK2MSFTN GP15.phx.gbl...
What I really whant, is the following:
I receive a xml instance and load it into XmlDocument. I have a XSD
specifying the full XML for the xml instance I have received. I now want to
iterate throw the xsd tree with a foreach-node/foreach-attribut the same way
as I can do it with my XmlDocument instance. I need this because I need
to do some comparison with the xml instance and the xsd and maybe fill in
some
"blank" values in the xml instance (not just a simple validate againt
XSD).
Hope you have a good idea on how to do this. I don't know much about
working
with XSD in .Net.

Regards Paw

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in
message news:#$******** ******@TK2MSFTN GP12.phx.gbl...
> what do you *really* want to do?
>
> do you want a generic xsd-to-xml generator? Something that can

contrive XML
> documents from any general XSD?
> or is there a particular XSD you want to generate for?
>
> one approach I have used is to use "xsd.exe /c" to generate classes, then> just instantiate the classes. Serialization of an instance of said class> produces an XML document that conforms to the XSD. example:
>
>

http://www.winisp.net/cheeso/srcview...ile=Xsd2xml.cs
>
>
> However, xsd.exe supports only a subset of W3C XML Schema. For example,> lists (as elements) are not well supported.
>
> -Dino
>
>
> "Paw Pedersen" <ne**@paws.dk > wrote in message
> news:Op******** ******@TK2MSFTN GP11.phx.gbl...
> > Is it possible to load a XSD and loop throw the nodes and attributes that
> > you whant filled out, and then generate a XML instance with the trees and
> > data that you have filled data in?
> > And how do you do that?
> >
> > Regards Paw
> >
> >
>
>



Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13489
by: obsidian8 | last post by:
Hi All, I have looked around for an answer to this question, but haven't found one as of yet. I'm trying to use javascript to dynamically create raido buttons. I am able to create them easily enough but they aren't clickable. It doesn't matter if I set them as checked or not, you can't manipulate them at all. The code I'm using appears...
3
9132
by: takarimasu | last post by:
How can i create an input object (text area,select) at runtime ? B.
3
5370
by: Richard Fritzler | last post by:
I was given the task of designing a complete web based document prep system. In simplest terms (using a msword explanation) create a database of merge fields, and a library of templates. Allow the webuser to select the template, merge his DB record, and produce a formatted document that can be printed or downloaded. We need to do this...
3
479
by: di | last post by:
I have a Access Database, and I would like to create a word document that (preferable would filter)links to ACCESS table or query. I would like to print the word document on the filtered record that I have selected in Access. for example if I have customer number (201) that I would like to merge over to a Word document. The word document is...
3
12350
by: sloesch | last post by:
I am working with VS.net 2003, framework 1.1, developing with VB.net, and ASP.net, and I would like to know how you can create a dynamic hyperlink on the fly to a document stored in a SQL database? I would like to create a VB.net function that would do this, and I found this class *System.Web.UI.WebControls.HyperLink*, but I can not find...
0
3214
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want to register new customer or companies they will enter the information in Windows Form and the program automaticaly creates the WORD document under...
4
12419
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
10
3950
by: SM | last post by:
Hello I'm trying to create a multi dimensional array in JavaScript, but after some reading i still can't figure out how to apply it to my model. Here it is: I have a list A and for each item in the list A i want to associate an undetermined number of items. The complication for me is the fact that the items to associate in list A are...
4
8265
by: sirjohnofthewest | last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man. Hi guys, I frequently visit this site to get answers to my problems and this one is really getting to me... I have a page that allows you to Browse Authors. There are three drop down boxes that auto-populate...
14
5168
RMWChaos
by: RMWChaos | last post by:
Firebug is reporting "too much recursion" when I attempt to create a child element in a parent that doesn't exist yet. The script should automatically create the missing parent before going on to create the child element. At the point where the script is supposed to call itself with the new properties to create the parent, it gives me the error...
0
7750
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7838
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5396
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5118
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1084
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.