473,230 Members | 1,968 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,230 software developers and data experts.

xsd.exe cannot generate schema

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.

When running xsd from the command line on the xml file it fails and returns
an Error Message as follows:
A DataTable named 'report' already belongs to this DataSet.

Why can xsd not tell the difference between <report> and <Silcn:report> when
they are clearly different?

cheers
--
PeterW
Nov 12 '05 #1
2 6863
DC
Correct, xsd.exe cannot generate (infer) a schema from such an xml file.
But it is pretty simple to do it yourself. For example, write the XSD like
so:

---- Begin Silcn.xsd ----

<xs:schema
targetNamespace="http://silcn.org/200309"
xmlns="http://silcn.org/200309"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://xmlprobe.com/200312"
attributeFormDefault="qualified"
elementFormDefault="qualified"

<xs:import namespace="http://xmlprobe.com/200312"
schemaLocation="XmlProbeReport.xsd" />

<xs:element name="silcn">
<xs:complexType>
<xs:sequence>
<xs:element ref="ns1:report" minOccurs="0" />
<xs:element ref="report" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="report" type="xs:string" />

</xs:schema>

---- End Silcn.xsd ----
---- Begin XmlProbeReport.xsd ----
<xs:schema
targetNamespace="http://xmlprobe.com/200312"
xmlns="http://xmlprobe.com/200312"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="qualified"
elementFormDefault="qualified"
<xs:element name="report" type="xs:string" />

</xs:schema>
---- End XmlProbeReport.xsd ----
Then, if you run xsd.exe to generate classes like so:

xsd.exe /c Silcn.xsd XmlProbeReport.xsd

you will get something like this:

---- Begin generated class ----

[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://silcn.org/200309")]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://silcn.org/200309",
IsNullable=false)]
public class silcn {

[System.Xml.Serialization.XmlElementAttribute(Names pace="http://xmlprobe.com/200312")]
public string report;

[System.Xml.Serialization.XmlElementAttribute("repo rt")]
public string report1;
}

---- End generated class ----
Some people find it simpler to go in the other direction - start with C# and
then generate XSD from it. To do this, write the C# (or VB) code similar
to the above, attributed with the proper namespaces and so on. Then compile
into an assembly (exe or DLL). Then do:

xsd /type:silcn <assembly>

...This will give you 2 xsd files, corresponding to what I provided above.

You can then round-trip, working in C# or VB and generating XSD, then
tweaking XSD and re-generating C# or VB. If you have a test driver, you
can verify that the C# code can actually de-serialize from a sample XML
stream. Eventually you will get to the right schema and class.

It is only in the inferring of the initial schema from an XML document, that
the obstacle arises. If you skip that step, you should be on your way. I
know this example is probably much simpler than what you need, but you
should be able to follow the solution pattern for larger, more complex
schema.

-Dino
..NET Developer Group
d i n o c h / online . m i c r o s o f t . c o m

"PeterW" <ns**@noemail.nospam> wrote in message
news:D1**********************************@microsof t.com...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.

When running xsd from the command line on the xml file it fails and
returns
an Error Message as follows:
A DataTable named 'report' already belongs to this DataSet.

Why can xsd not tell the difference between <report> and <Silcn:report>
when
they are clearly different?

cheers
--
PeterW

Nov 12 '05 #2
I had gone down the route of constructing xsds myself before I posted the
question. You did show me how to fix some things I got wrong.

I resorted to updating the incoming xml files with a transformation as a
kludge and then extracting a schema which is not a preferred option when
updating Vocabularies and Policies.

The original question is still valid however, being if a namespace is
defined and is not qualified with a prefix, it should apply to all
unqualified elements in the file by default as I understand it. I would have
thought it should be dealt with by default by any schema inferencing tool
such as xsd.exe. I would still like to understand why it is not as a matter
of interest rather than to fix a problem.

The reason I ask is that BizTalk makes a lot of use of xsd schemas.
Maintaining such systems should be as easy as possible and if possible be
able to be done by non programmers. The harder it is to create schemas the
more of a maintainability nightmare there is with evolving business rules
using tools such as the Business Rule Composer as business changes over time.
If that is not the case then instead of making reliance on skills less over
time the converse is true. You can see where I am going.

cheers
--
PeterW
"DC" wrote:
Correct, xsd.exe cannot generate (infer) a schema from such an xml file.
But it is pretty simple to do it yourself. For example, write the XSD like
so:

---- Begin Silcn.xsd ----

<xs:schema
targetNamespace="http://silcn.org/200309"
xmlns="http://silcn.org/200309"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://xmlprobe.com/200312"
attributeFormDefault="qualified"
elementFormDefault="qualified"


<xs:import namespace="http://xmlprobe.com/200312"
schemaLocation="XmlProbeReport.xsd" />

<xs:element name="silcn">
<xs:complexType>
<xs:sequence>
<xs:element ref="ns1:report" minOccurs="0" />
<xs:element ref="report" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="report" type="xs:string" />

</xs:schema>

---- End Silcn.xsd ----
---- Begin XmlProbeReport.xsd ----
<xs:schema
targetNamespace="http://xmlprobe.com/200312"
xmlns="http://xmlprobe.com/200312"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="qualified"
elementFormDefault="qualified"


<xs:element name="report" type="xs:string" />

</xs:schema>
---- End XmlProbeReport.xsd ----
Then, if you run xsd.exe to generate classes like so:

xsd.exe /c Silcn.xsd XmlProbeReport.xsd

you will get something like this:

---- Begin generated class ----

[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://silcn.org/200309")]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://silcn.org/200309",
IsNullable=false)]
public class silcn {

[System.Xml.Serialization.XmlElementAttribute(Names pace="http://xmlprobe.com/200312")]
public string report;

[System.Xml.Serialization.XmlElementAttribute("repo rt")]
public string report1;
}

---- End generated class ----
Some people find it simpler to go in the other direction - start with C# and
then generate XSD from it. To do this, write the C# (or VB) code similar
to the above, attributed with the proper namespaces and so on. Then compile
into an assembly (exe or DLL). Then do:

xsd /type:silcn <assembly>

...This will give you 2 xsd files, corresponding to what I provided above.

You can then round-trip, working in C# or VB and generating XSD, then
tweaking XSD and re-generating C# or VB. If you have a test driver, you
can verify that the C# code can actually de-serialize from a sample XML
stream. Eventually you will get to the right schema and class.

It is only in the inferring of the initial schema from an XML document, that
the obstacle arises. If you skip that step, you should be on your way. I
know this example is probably much simpler than what you need, but you
should be able to follow the solution pattern for larger, more complex
schema.

-Dino
..NET Developer Group
d i n o c h / online . m i c r o s o f t . c o m

"PeterW" <ns**@noemail.nospam> wrote in message
news:D1**********************************@microsof t.com...
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.

When running xsd from the command line on the xml file it fails and
returns
an Error Message as follows:
A DataTable named 'report' already belongs to this DataSet.

Why can xsd not tell the difference between <report> and <Silcn:report>
when
they are clearly different?

cheers
--
PeterW


Nov 12 '05 #3

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

Similar topics

0
by: Almoni | last post by:
Hi, I have a few .xsd files that include each other in the following way: <!-- lets call the main schema file AA.xsd and it includes BB.xsd inside it --> <xs:schema...
1
by: MB | last post by:
I am trying to work out why .NET 1.1 SP1 (XSD.exe) cannot generate wrapper classes for LandXML 1.0 or 1.1 (http://www.landxml.org/spec.htm) and yet .NET 2.0 (BETA 1) can for LandXML 1.0. The...
2
by: Vicki | last post by:
Using VS2005 beta 2, I have an xsd provided by a vendor that I want to make into a strongly typed data set. In VS 2003 the MSDataSetGenerator tool gives a similar error, which I was told was to be...
1
by: comic_rage | last post by:
Hi, I am writing code with C# to generate xml schema, however, the following code generate a UTF-16 in the first line. This will create some problems. How can get the code/missing what part of...
8
by: Phil Lee | last post by:
I'm sure this is possible but I just can't see how to do it. I want to add schemas to my solution and have C# classes automatically generated from them. I can see how to generate typed DataSet's...
2
by: andy gilman | last post by:
When I generate an xsd *schema* I get something like : <?xml version="1.0" encoding="utf-16"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="AccountsReceivable">...
3
by: Lord0 | last post by:
I am trying to implement variable content containers using an abstract type and type substitution. My schema is as follows: <?xml version="1.0" encoding="UTF-8"?> <schema...
0
by: =?Utf-8?B?TGFzdGJ1aWxkZXJz?= | last post by:
Hi all, I have a weird problem which has been causing me a headache for the last two days. I have to dynamicly generate a schema in memory and load it into a dataset in memory to be returned...
0
by: mmaslar | last post by:
Can Visual Studio ('05 or '08) generate a WSDL file with an external Schema file? eg. Instead of placing the schema within the WSDL file, generate it in a separate XSD file? In other words......
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.