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.
unqualified elements in the file by default as I understand it. I would have
such as xsd.exe. I would still like to understand why it is not as a matter
The reason I ask is that BizTalk makes a lot of use of xsd schemas.
able to be done by non programmers. The harder it is to create schemas the
using tools such as the Business Rule Composer as business changes over time.
time the converse is true. You can see where I am going.
"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
>
>