473,651 Members | 3,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Constructing XML file based on Schema

Sek
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.

What would be the ideal way to achieve this?

TIA.
Sek

Sep 17 '06 #1
5 2268


Sek wrote:

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.
With .NET 2.0 you can build an XmlSchemaSet
<http://msdn2.microsoft .com/en-us/library/system.xml.sche ma.xmlschemaset .aspx>
which gives a logical view on the compilation of all schemas and you can
then walk the schema object model
<http://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspxand
create elements and attributes as needed.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 17 '06 #2
Sek
Thanks Martin.

Is there any way to achieve this in 1.1?
Martin Honnen wrote:
Sek wrote:

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.

With .NET 2.0 you can build an XmlSchemaSet
<http://msdn2.microsoft .com/en-us/library/system.xml.sche ma.xmlschemaset .aspx>
which gives a logical view on the compilation of all schemas and you can
then walk the schema object model
<http://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspxand
create elements and attributes as needed.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 17 '06 #3


Sek wrote:

Is there any way to achieve this in 1.1?
..NET 1.x also has a SOM (Schema Object Model) but slightly different, see
<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/cpguide/html/cpconXSDSchemaO bjectModelSOM.a sp>
for details.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 17 '06 #4
Sek
Martin,

I did reference some of those topics, but may not be to fullest extent.

I have advanced to an extent in reading the contents of schema files.
In brief, the schema files i am using are nested, in the sense, i have
the following:
-Parent.xsd [Schema directly used by the xml file]
-Child1.xsd, Child2.xsd [Both the schemas are import/included by the
Parent.xsd]
-Types1.xsd, Types2.xsd [Contains some basic types import/included by
the Childx.xsd files]

Basically, the schema is not so complicated, but i have issues
pertaining to nillable types, wherein i have to use "xsi:nil=tr ue" for
emplty nillable type elements. My approach is to parse through the
schema recursively and get the list of type declaration for
XmlSchemaElemen ts.
Then for every empty element to be written to xml file, i check the
above list for nillable type, in which case i add "xsi:nil=tr ue" to the
element.

Following is the code for obtaining list of all xmlschemaelemen ts
recursively:

-----BEGIN-----
XmlSchemaCollec tion o = new XmlSchemaCollec tion();
o.Add(sIssueTyp e,new XmlTextReader(s SchemaFile),new XmlUrlResolver( ));
_oCollecElement s = new ArrayList();

foreach(XmlSche ma ienmr in o)
{
foreach(object item in ienmr.Elements. Values)
{
_oCollecElement s.Add(item);
}
}
--------END------

The above approach lists all the xmschemaelement s from Parent.xsd,
Child1.xsd and Child2.xsd , but doesn't list the xmlschemaelemen ts in
Types1.xsd and Types2.xsd. The Types1.xsd is imported by Child1.xsd
using the following statement <xs:include schemaLocation= "Types1.xsd "
/within the Child1.xsd file. So, i am expecting the
XmlSchemaCollec tion to resolve the types in the Types1.xsd file as
well.

Does my approach make any sense to you?

TIA.
Sek

Martin Honnen wrote:
Sek wrote:

Is there any way to achieve this in 1.1?

.NET 1.x also has a SOM (Schema Object Model) but slightly different, see
<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/cpguide/html/cpconXSDSchemaO bjectModelSOM.a sp>
for details.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 17 '06 #5
"Sek" <se****@gmail.c omwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Martin,

I did reference some of those topics, but may not be to fullest extent.

I have advanced to an extent in reading the contents of schema files.
In brief, the schema files i am using are nested, in the sense, i have
the following:
-Parent.xsd [Schema directly used by the xml file]
-Child1.xsd, Child2.xsd [Both the schemas are import/included by the
Parent.xsd]
-Types1.xsd, Types2.xsd [Contains some basic types import/included by
the Childx.xsd files]

Basically, the schema is not so complicated, but i have issues
pertaining to nillable types, wherein i have to use "xsi:nil=tr ue" for
emplty nillable type elements. My approach is to parse through the
schema recursively and get the list of type declaration for
XmlSchemaElemen ts.
Then for every empty element to be written to xml file, i check the
above list for nillable type, in which case i add "xsi:nil=tr ue" to the
element.

Following is the code for obtaining list of all xmlschemaelemen ts
recursively:

-----BEGIN-----
XmlSchemaCollec tion o = new XmlSchemaCollec tion();
o.Add(sIssueTyp e,new XmlTextReader(s SchemaFile),new XmlUrlResolver( ));
_oCollecElement s = new ArrayList();

foreach(XmlSche ma ienmr in o)
{
foreach(object item in ienmr.Elements. Values)
{
_oCollecElement s.Add(item);
}
}
--------END------

The above approach lists all the xmschemaelement s from Parent.xsd,
Child1.xsd and Child2.xsd , but doesn't list the xmlschemaelemen ts in
Types1.xsd and Types2.xsd. The Types1.xsd is imported by Child1.xsd
using the following statement <xs:include schemaLocation= "Types1.xsd "
/within the Child1.xsd file. So, i am expecting the
XmlSchemaCollec tion to resolve the types in the Types1.xsd file as
well.

Does my approach make any sense to you?
Yes, but you would need to recursively walk the included / imported schemas
using XmlSchema.Inclu des:

foreach (XmlSchemaImpor t included in schema.Includes )
{
if (included.Schem a != null)
{
Recurse(include d.Schema);
}
}

John
Sep 17 '06 #6

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

Similar topics

1
4062
by: Vitor Rodrigues | last post by:
Hi!! I have a little problem i'm trying to resolve. I've a .xml and it's schema (.xsd). i need to create a XSL file to transform the XML one, but i only now what data types the .xml file has by reading the ..xsd one. There are some examples related with that? An example is:
1
1650
by: Scott Brady Drummonds | last post by:
Hi, everyone, I'm designing my first XML-based application and am stuck on an issue that I presume is pretty simple. I'm trying to write a schema that can be used to validate my XML file. However, I want to define components of this schema in different files so that I can do isolated tests on these subsections. As an example, consider this XML file: <container> <name>Me</name>
0
1173
by: Zbyszek Cybulski | last post by:
Hello, I was trying to find anything on the topic in the archives but failed. This may seem a well-known issue but I am a newbie on XML stuff. I have created an XML Schema file (XSD) which defines the structure and relations in a data set. And based on this, I have created an XML file which is my data set. The data set file became too big to be easily edited, so I wanted to split it into smaller chunks and make a master data set,...
1
3937
by: Jiho Han | last post by:
I am thinking of embedding my schemas as embedded resources instead of reading it using URI at run-time. I came across some snags while trying to do just that such as, previously unknown to me, XmlValidatingReader.Schemas.Add was using XmlValidatingReader.Resolver to resolve my schemas using the URI method. Resolver property was never set, so the reader simply ignored any external references even though one of the schema explicitly imports...
0
4692
by: Peter | last post by:
I am having a problem reading an Excel file that is XML based. The directory I am reading contains Excel files that can be of two types. Either generic Microsoft based or XML based. I am reading the Microsoft based files with an OleDbDataAdapter. Then filling the contents of the first worksheet into a dataset. However when I try to add the XML based file to my dataset using an XmlTextReader I can never seem to get it to save to a...
1
6135
by: donnie.hale | last post by:
Question: What's the "canonical" way to import an existing XSD schema file into VS2005 in such a way that I can use standard C# object / property techniques to create content of that schema type and ultimately generate an XML file based on that schema? Background: I've been given an XSD file by a 3rd party. I need to generate XML files based on that schema. Note that is ***not*** for web service
13
2887
by: Jerry C | last post by:
I am using some sample code from gotdotnet to Create DataSet mappings from a xsd schema. I am geting this error. code and error below. I might mention there is also a publictypelibrary file with this file I may have to use it in some way. I am very new at XML so some examples or articles would be helpfull. The error is:
3
2073
by: Gary | last post by:
Hi in a simple application that consists of a couple of user input forms. I'm wondering what the difference is between using a database technology and a plain text file? I've been working on this program for a week or so now and its a hobby project. I have never understood how to work with databases in visual studio (although I have strung together a couple of Microsoft access databases in the past, by trial and error.) As I don't...
13
8148
by: Bill Nguyen | last post by:
Is it possible to create your won XSD to use with .NET based on an XML content? For example the one below: <?xml version="1.0"?> <pcats:FuelsDoc xmlns="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="NAXML-FuelPrice15.xsd"> <pcats:TransmissionHeader>
0
8361
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
8278
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
8807
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
8701
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
6158
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
5615
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
4144
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...
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
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.