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
0
nspw (3)
6/14/2005 2:36:02 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
741 Views

Similar Articles

[PageSpeed] 41

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(Namespace="http://silcn.org/200309")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://silcn.org/200309", 
IsNullable=false)]
public class silcn {

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

    [System.Xml.Serialization.XmlElementAttribute("report")]
    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" <nspw@noemail.nospam> wrote in message 
news:D195D944-7A79-4CBE-8B2D-5BA0039CF28D@microsoft.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 


0
dinoch1 (221)
6/14/2005 5:11:50 PM
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(Namespace="http://silcn.org/200309")]
> [System.Xml.Serialization.XmlRootAttribute(Namespace="http://silcn.org/200309", 
> IsNullable=false)]
> public class silcn {
> 
>     [System.Xml.Serialization.XmlElementAttribute(Namespace="http://xmlprobe.com/200312")]
>     public string report;
> 
>     [System.Xml.Serialization.XmlElementAttribute("report")]
>     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" <nspw@noemail.nospam> wrote in message 
> news:D195D944-7A79-4CBE-8B2D-5BA0039CF28D@microsoft.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 
> 
> 
> 
0
nspw (3)
6/15/2005 3:16:10 PM
Reply:

Similar Artilces:

trouble validating against xsd
Hello, I have an xsd file that I'm trying to use to validate some xml against. I'm hoping this is a simple problem, but I just don't see it. I get the error "The 'role' element is not declared." when trying to validate this xml: <users> <user id="jon" pwd="pass"> <roles><role>Admin</role></roles> </user> </users> Against this schema: <?xml version="1.0" encoding="utf-8" ?> <xs:schema elementFormDefault="unqualified" xmlns="" xmlns:xs=&...

Mapisp32.exe
When doing send and receive in outlook 97 Mapisp32 goes up to 99% on the cpu usage and outlook appears to hang. Office 97 in running on windows XP using internet mail. Any help would be much appreciated aidan wrote: > When doing send and receive in outlook 97 Mapisp32 goes up to 99% on > the cpu usage and outlook appears to hang. Office 97 in running on > windows XP using internet mail. > > Any help would be much appreciated Not sure if this will help, but see http://www.slipstick.com/addins/SERVICES/imep.htm Also note - OL97 is old, unsupported, and was buggy at rele...

About XSD Parser
Hello, I have a XSD file which has the following format: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com" elementFormDefault="qualified"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading&q...

Entity XSD schemas are invalid
Hi, As part of doing a custom integration using BizTalk 2004, we need to do mappings between MS CRM and other applications. However the xsd's provided with the SDK and the stored procedures generating them are/produce invalid (non-w3c compliant) xsd. It might be an idea for someone in the MS CRM dev group to go over these xsd's with a validator and fix the incorrect sections, including th generating stored procedures so updated schemas can be made available for integration purposes. Best Regards Thomas Scheelhardt I have found the majority of examples in the SDK are incorrect an...

Ignoring Elements in XSD
How do I write a schema that is only validating elements: 1,4,7,8,9 and ignores every other element? I also need to not to care about the order of the elements or how many are in between elements that I am trying to validate. XML: <root> <element1 /> <element2 /> <element3 /> <element4 /> <element5 /> <element6 /> <element7 /> <element8 /> <element9 /> </root> XSD: <xs:element name="root"> <xs:complexType> ...

Retrieving default values specified from XML Schema file
Hi All, I have an VS.NET 2003 app which will be processing XML files, some of which will have empty elements (for example, <Item />). I have an XSD file which should supply default values, but I am not able to read these plugged in value using an XMLDocument object. The validation is working fine--it's just not providing any default values. Has anybody tried this? Am I must be missing something? This is one of those that "should be simple..." Here's a simplifed version of the code and XML files: XmlDocument xmldoc = new XmlDocument(); XmlSchemaCollection my...

MIDL.exe , where is it stored in VC7 ?
Hi, What is the path of MIDL in VC7 Thanks, sandSpiderX Hallo sandSpider! > What is the path of MIDL in VC7 Here: C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\Bin -- Martin Richter [MVP] WWJD "In C we had to code our own bugs. In C++ we can inherit them." FAQ : http://www.mpdvc.de Samples: http://www.codeguru.com http://www.codeproject.com Hi Martin, Thanks a lot... ...

C:\Programfiles(x86)\Microsoft Office\Office 12\winword.exe
I am having trouble with little white boxes containing red x's. I suddenly cannot see any pictures when I use the print screen. I get to word and paste and a blank box comes up. I have reinstalled checked for viruses etc... Sometimes when I log off it says "You are missing a component." C:\Programfiles (86)\Microsoft Office\Office 12\winword.exe I am going crazy as I need this to work. I am also having trouble with websites and little white boxes with red x's. I cannot download the flash player whereas before I did not have this problem. Any help would b...

How can I generate a user friendly error message when validating XML against a schema?
Hello When validating xml against a schema, the most frequent error I get is something like "The 'FOO' attribute has an invalid value according to its data type. An error occurred at , (25, 913)". That error message is not very user friendly, so I'd like to extract the data in the failing node along with its parent node data, and show that to the user. Do you know a way to do this? I don't think there's any other information about the error position than the line number and position. Yes, line number and position is the only information that you have to...

Newprof.exe
I have an issue when using Outlook 2002. When I sign on to my laptop (using Domain credentials) I get an error from outlook about the profile generator. In the Event Viewer, I see the following: Description: Faulting application newprof.exe, version 5.5.3121.0, faulting module ntdll.dll. version 5.1.2600.1217, fault address 0x0000b2ab I have tried multiple uninstall/reinstalls and mulitple "Detect and repair" with no effect. ...

can't repair my PST file with scanpst.exe
Hi, I am using outlook 2003, and my outlook have some problem its having 2 GB of data and i am try to repair with Scanpst.exe but it says the error that the file is too large and unable to repair the PST. Please help me to get off this problem. Thanks in Advance. Balaji.k See if the info here helps: http://www.slipstick.com/problems/repair2gbpst.htm "balaji" <balajek_hwe@hotmail.com> wrote in message news:eg0zfjcIGHA.3144@TK2MSFTNGP10.phx.gbl... > Hi, > > > I am using outlook 2003, and my outlook have some problem its having 2 > GB of data an...

using embedded .xsd vs file based .xsd
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 the other one. I verified this by removing the referred schema from the schema collection, and the code chugged along fine. But when I changed the code to ...

Can I save application as .exe file
I have created several successful Access applications in the past. I need an application that can be maintained on several different computers which may not all have MS Office installed. Can I put the complete database on a CD so different people can update the data? I guess that this means the application would have to be a .exe file and maybe use CD-RW CDs so it can be written to on different computers. Really Gone There's never been an ability to create an executable from an Access database, and I wouldn't expect there ever to be such a capability. Take a look a...

Dynamics.exe error
I get this program error on the clinets when a client tries to logon to Great Plains. We are going to go live in july with version 7.5. and this is the errorI get "dynamics.exe has generated errors and will be closed by Windows. You will need to restart the program. Can anyone help me with this problem!! Thanks E Repost to microsoft.public.greatplains Matt Parks ---------------------------------------- ---------------------------------------- On Wed, 12 May 2004 07:31:02 -0700, "Edward Perrier" <eperrier@birosaw.com> wrote: I get this program error on the clinets w...

outlook.exe problem
I have been pulling my hair out trying to figure this problem out. When I open outlook it will remain open for about 5 minutes before it goes to this window. "Outlook.exe has generated errors and will be closed down by Windows. You will need to restart the program. An error log has been created." Once this happens outlook shuts down. I have attempted to run a command in run mode that eliminates the preview pane and many other features, this is called "safe" from what I read. I need full functionality of this program and am having a hard time not being able to...

Problems with XML, XSD, Web, Services & InfoPath
Hi all, Have been playing about with web services but unable to achieve what I am wanting and in attempts finding strange problems. I have created a web service for retrieving customer data and for updating the data using datasets. I have created a XML schema. I decided to use InfoPath for testing things out. Works great for getting the data. The data table on SQL Server 2000 allows nulls. If I was to change this I would have to split my customers into 2 tables. The table allows customer details to be stored as an individual or organisation. As a result some fields don't require ...

Error messages produced by vc .exe: win32 error 11
Hello and thanks for helping. I have been developing a program on a win98 computer but then switched to a w2k computer for a while. Now I have to go back to the win98 computer and support the program on other win98 computers. Problem is, when I reinstalled VC++, cleaned then rebuilt all, then executed, the following 2 dialog boxes appeared: 1)"Error starting program" "Program appears to be corrupt" 2) "Microsoft Visual C++" "Incorrect format (win32 error 11)" this same project, when compiled for win98 3 months ago, worked fine. This same project...

suppressing xsd namespace declarations with XmlSerialize?
Hi... I'm just starting to play around with xml serialization. Is there any way to suppress the xsd and xsi declarations in the resulting xml? It doesn't appear that they're used but they come out anyway. Thanks -Mark Hi Mark, We need to perform more research on this issue . We will reply here as soon as possible. If you have any more concerns on it, please feel free to post here. Thanks for your understanding! Best regards, Wen Yuan Hi Mark, Thanks for your wait. If you don��t need xsi and xsd declaration with xml serialization, you can use XmlSerializerNamesp...

Validating XML against XSD where XSD has includes
I have 2 Xsd's The one contains basic type definitions <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:simpleType name="TrueFalse"> <xs:restriction base="xs:NMTOKEN"> <xs:enumeration value="true"/> <xs:enumeration value="false"/> </xs:restriction> </xs:simpleType> </xs:schema> The other includes the previous XSD so th...

XSD #2
I have an XML that when I try to create an xsd schema for it it would error out and say something about duplicate keys. Does that mean that the XML is bad? Thanks How are you trying to create a schema for it? Are you using http://apps.gotdotnet.com/xmltools/xsdinference/ -- This posting is provided "AS IS" with no warranties, and confers no rights. <john88m@hotmail.com> wrote in message news:eCcFyFK1DHA.3416@tk2msftngp13.phx.gbl... > I have an XML that when I try to create an xsd schema for it it would error > out and say something about duplicate keys. Does that me...

Application exe name and path?
How can I get application path + .exe name? Example: CString cAppName = theApp->ExeName; //cAppName == "c:\projects\my_app.exe" Thank you. "Oliver Young" <none> wrote: > > How can I get application path + .exe name? Look up GetModuleFileName() -- Tim Slattery MS MVP(DTS) Slattery_T@bls.gov Actually, I think the answer you were looking for is to look up AfxGetAppName(). GetModuleFileName() requires a module handle, and is aimed at DLL support (I've never even used it for EXEs, and have no idea if it would even work). >-----Origin...

Auto generating a Directory Structure Diagram
Hello All, I will like to find a quick to automatically generate a Diagram of the Directory Structure (including files) of my C:\ drive. I think Visio can do this, but I am unable to figure out how to do it. Any ideas? In Peace, Saqib Ali http://validate.sf.net There is not native function in Visio to perform this you would have to create it as code. It would probably be easier to use the standard activex controls available; treeview, common controls, etc. Al "Saqib Ali" <rumionfire@gmail.com> wrote in message news:%23YuRaKP9EHA.1564@TK2MSFTNGP09.phx.gbl... > Hell...

TpScrex.exe
While looking through the the list under C:/Program Files, I noticed a folder called TpScrex. I have no idea where this came from or what it does. My computer is home built and I don't recall installing it. Can anyone give me more information on what this thing is and if it's OK to uninstall it? Thanks. Google gave me this: http://www.processlibrary.com/directory/files/tpscrex/ In short, it appears to be a diagnostic utility for a ThinkPad... If this is not your type of system, I'd run a scan for malware.... "Jackpine" <Jackpine@discussions.microsof...

Distinguish 32bit and 64bit binaries (exe,dll) ?
Hello, How do I know if binary file I have is compiled for x86-32 or x86-64 ? For example some file from windows os binaries. I have visual studio by the way - if tools are needed. thanks Vilius Hi Vilius! > How do I know if binary file I have is compiled for x86-32 or x86-64 ? > For example some file from windows os binaries. > > I have visual studio by the way - if tools are needed. www.dependecywalker.com But an other question: WHY do you need to know it? Normally you don't need to know it... -- Greetings Jochen My blog about ...

Money.exe process
So, I checked out the FAQ's but I still have the Money.exe process issue where I have to Kill it to restart Money. Any other updates to fixing it? ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- Andrew I noticed through the use of a program called Active Ports that Money.exe will remain running long after the program is closed as long as there are still ports open that are associated with M...