473,785 Members | 2,878 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 17656
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
13529
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 below: function test(){ componentMainTable = document.getElementById("mycomponent");
3
9146
by: takarimasu | last post by:
How can i create an input object (text area,select) at runtime ? B.
3
5394
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 without specialized software on the client, since it will be universally available to webusers. We...
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 a template that I would like to use regularly. Thanks so Much for anyone that can WALK me thru...
3
12364
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 any examples on generate a dynamic hyperlink. Basically, I want my function to generate an embedded...
0
3232
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 specific folder under application path. Once the empty word file created than ask user if they want...
4
12442
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
3993
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 undetermined.
4
8284
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 via AJAX. I have a file which it calls and returns the dynamically built XML file in the boxes...
14
5197
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 and looks like it's looping the function continuously. It seems that "id : attrib" (line 192) is...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7500
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.