473,799 Members | 2,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to instantiate xml doc from schema (xsd) file

Hi everyone,

Does anyone know how to instantiate, or create an XML document file (either
using DOM or Readers) from an XML schema (xsd) file?

I'm trying to develop an application that can handle different xml doc
structures, but at the same time I need to create these documents, even if
there's no content. So I was planning to drive it with schema files (xsd),
but I haven't figured out from looking at the .net SOM how to create the xml
document from the schema.

Thanks,
--Ader.
Nov 12 '05 #1
4 5059
This article
http://msdn.microsoft.com/library/en...xsdcodegen.asp
describes how to generate a class from an XSD, using CodeDom. You can then
instantiate the class, fill it, then serialize to a stream and instantiate
an XmlDocument from that stream.

A similar approach, but using the xsd.exe tool, is here:
http://cheeso.members.winisp.net/src...ile=Xsd2xml.cs

-D

"A. Gonzalez" <no**@dontspam. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi everyone,

Does anyone know how to instantiate, or create an XML document file
(either using DOM or Readers) from an XML schema (xsd) file?

I'm trying to develop an application that can handle different xml doc
structures, but at the same time I need to create these documents, even if
there's no content. So I was planning to drive it with schema files
(xsd), but I haven't figured out from looking at the .net SOM how to
create the xml document from the schema.

Thanks,
--Ader.

Nov 12 '05 #2
Thanks,

I'll check that out!

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:e%******** *******@TK2MSFT NGP11.phx.gbl.. .
This article
http://msdn.microsoft.com/library/en...xsdcodegen.asp
describes how to generate a class from an XSD, using CodeDom. You can
then instantiate the class, fill it, then serialize to a stream and
instantiate an XmlDocument from that stream.

A similar approach, but using the xsd.exe tool, is here:
http://cheeso.members.winisp.net/src...ile=Xsd2xml.cs

-D

"A. Gonzalez" <no**@dontspam. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi everyone,

Does anyone know how to instantiate, or create an XML document file
(either using DOM or Readers) from an XML schema (xsd) file?

I'm trying to develop an application that can handle different xml doc
structures, but at the same time I need to create these documents, even
if there's no content. So I was planning to drive it with schema files
(xsd), but I haven't figured out from looking at the .net SOM how to
create the xml document from the schema.

Thanks,
--Ader.


Nov 12 '05 #3
The following MSDN article describes a tool to generate XML documents from a
schema using the .NET SOM:
http://msdn.microsoft.com/library/de...tml/xmlgen.asp

Thanks,
Priya

"A. Gonzalez" <no**@dontspam. com> wrote in message
news:eL******** ******@TK2MSFTN GP15.phx.gbl...
Thanks,

I'll check that out!

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:e%******** *******@TK2MSFT NGP11.phx.gbl.. .
This article
http://msdn.microsoft.com/library/en...xsdcodegen.asp
describes how to generate a class from an XSD, using CodeDom. You can
then instantiate the class, fill it, then serialize to a stream and
instantiate an XmlDocument from that stream.

A similar approach, but using the xsd.exe tool, is here:
http://cheeso.members.winisp.net/src...ile=Xsd2xml.cs
-D

"A. Gonzalez" <no**@dontspam. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi everyone,

Does anyone know how to instantiate, or create an XML document file
(either using DOM or Readers) from an XML schema (xsd) file?

I'm trying to develop an application that can handle different xml doc
structures, but at the same time I need to create these documents, even
if there's no content. So I was planning to drive it with schema files
(xsd), but I haven't figured out from looking at the .net SOM how to
create the xml document from the schema.

Thanks,
--Ader.



Nov 12 '05 #4
Priya,

Thanks al lot... that was exactlly what I was looking for... well, not
exactly.... What I want to do is instantiate
a DOM from an xsd file. Although, your technique is a start to go from xsd
to xml file, I can't use your solution because of its reliance on .net 2.0
types. I'm still using .net v1.1, and I'm having trouble finding the
definition for things like XmlTypeCode enumerated type (the online doc for
..net 2.0 doesn't have it either). Also, you use your own generated
instance-value tree to generate the output xml file. I'm starting to work
on a similar thing but using DOM XmlNodes, so I actually construct a live
xml document.

I couldn't use Dino's suggested solution with code generation either because
that binds my client code to specific types, which is the opposite of what I
want to achieve, which is to keep my app generic. Even though I could use
reflection to keep everything dynamic and handle diffeent schemas and
document types, Dino's solution still seems an overkill for my purpose.

It's a pity that what seems to be straight-foward functionality that should
be provided by the framework, it's not. I hope .net v2.0 does better with
SOM to DOM support.

Thanks.
--Ader.

"Priya Lakshminarayana n [MSFT]" <pr****@online. microsoft.com> wrote in
message news:41******** @news.microsoft .com...
The following MSDN article describes a tool to generate XML documents from a schema using the .NET SOM:
http://msdn.microsoft.com/library/de...tml/xmlgen.asp
Thanks,
Priya

"A. Gonzalez" <no**@dontspam. com> wrote in message
news:eL******** ******@TK2MSFTN GP15.phx.gbl...
Thanks,

I'll check that out!

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:e%******** *******@TK2MSFT NGP11.phx.gbl.. .
This article
http://msdn.microsoft.com/library/en...xsdcodegen.asp
describes how to generate a class from an XSD, using CodeDom. You can
then instantiate the class, fill it, then serialize to a stream and
instantiate an XmlDocument from that stream.

A similar approach, but using the xsd.exe tool, is here:

http://cheeso.members.winisp.net/src...ile=Xsd2xml.cs

-D

"A. Gonzalez" <no**@dontspam. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> Hi everyone,
>
> Does anyone know how to instantiate, or create an XML document file
> (either using DOM or Readers) from an XML schema (xsd) file?
>
> I'm trying to develop an application that can handle different xml doc> structures, but at the same time I need to create these documents, even> if there's no content. So I was planning to drive it with schema files> (xsd), but I haven't figured out from looking at the .net SOM how to
> create the xml document from the schema.
>
> Thanks,
> --Ader.
>



Nov 12 '05 #5

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

Similar topics

0
4228
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > <password>brown</password> > </userlogin> > Above is my schema instance.
2
10762
by: Vagabond Software | last post by:
I have translated a DTD to an XML Schema (XSD) file by hand, and the Schema View in Visual Studio .NET 2003 seems to diplay everything properly. However, when I specify the schemalocation in my xml files, VS.NET still reports that no schema could be located. Here are the relevant (maybe) portions of the files: FROM THE SCHEMA FILE (mydoc-v2.xsd) <?xml version="1.0" encoding="utf-8" ?> <xs:schema...
3
6061
by: Shailendra Batham | last post by:
hi guys I need your suggestions / opinion for doing this the right way. I have a XML and a Schema for the same What I want is when its validated against the schema, it should give custom errors saying what happened and where...... is it possible to do that ? for eg. if the Attribute is missing or invalid in the following element <Watch ID="999d999">
1
2327
by: Dan Bass | last post by:
There's an XML message I have, that has no namespace information. Then there is a XSD schema that is must validate against, but this has a targetNamespace and xmlns of "http://www.wbf.org/xml/b2mml-v02". How do I get this XML to validate against the Schema in C#? If I use XmlSpy (2005 home edition) to perform the validation, it first inserts namespace and schema information into the XML before validating. Validation then seems to work if...
6
2594
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
2
6935
by: PeterW | last post by:
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as follows: <silcn:silcn xmlns:silcn='http://silcn.org/200309' xmlns='http://xmlprobe.com/200312'> it contains an element <report> off the root and also a separate <Silcn:report> again off the root.
2
2254
by: Frosty | last post by:
Howto make datagrid enforce rules of xml schema? Created xml schema in the designer. Constraints created there using the following <xs:simpleType name="zipcode"><xs:restriction base="xs:string"><xs:pattern value="\d{5}" /></xs:restriction></xs:simpleType Datagrid does not enforce this rule, even though dataGrid1_Validating() is called. dataset.WriteXml() saves withouth any warning, but
4
7747
by: Stan R. | last post by:
Hello, I have xmllint and xsltproc installed and running on both my linux and win32 platforms, all seems good. I have a couple questions though. 1) If I have an external dtd file, which is included in my xml file, like <!DOCTYPE userlist SYSTEM "test.dtd">
5
2281
by: Sek | last post by:
Hi Folks, I would like to create a XML file that adhere to the Schema definition files. My schema definition files import/include further XSD files and internal references can be to a depth of two or three. The data required for the creation of XML are present in the form of user defined data structures.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
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
10473
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
10025
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...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6804
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();...
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2937
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.