Mike,
to solve these sorts of problems, you can try working in the opposite
direction. When I want to de-serialize a document of a particular schema,
here's what I do:
1. infer the schema from the document using xsd.exe (only necessary if no
schema is available. Really, the doc publisher should give you a schema,
you shouldn't have to infer it)
2. generate classes from that schema, using xsd.exe /c
3. build a test driver (20 lines of code) that instantiates the class and
then serializes it. Compare to the xml document you are trying to match.
You can then iterate on your schema or the generated class, tweaking it to
match what you want.
-----
In your case,
A. the
xmlns:someobj=http://www.abcinc.com/objectdefinition
is not valid XML. Need quotes around this namespace value.
B. you did not specify the rest of the XML doc, but the assignment of the
someobj prefix corresponding to the http://www.abcinc.com/objectdefinition
namespace seems to be unnecessary. This will not break your
de-serialization, but it is superfluous.
C. the class I got by following the steps above was this:
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.abcinc.com/objectdefinition")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.abcinc.com/objectdefinition",
IsNullable=false)]
public class SomeObject {
public string SomeField;
}
And it de-serialized your XML (with the necessary quotes added, and one
element added for illustration) just fine.
D. to produce a similar XML doc by serializing, use
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add( "", "http://www.abcinc.com/objectdefinition" ); // this will be
the default (no prefix) namespace in the XML doc, eg, xmlns="..."
before serializing, and be sure to specify this ns in the Serialize() step.
s1.Serialize(xmlWriter, so, ns);
-Dino
> Hello all,
>
[quoted text clipped - 52 lines]
>
> Mike
Christoph Schittko [MVP] - 23 Dec 2004 19:23 GMT
Mike and Dino,
Inferring schemas and classes is definitely a good way to go. Note that
there are newer tools on GDN for inferring schemas from classes [0] and
creating classes from schemas [1]. These tools should address some of
the shortcomings of xsd.exe.
HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko
[0] http://apps.gotdotnet.com/xmltools/xsdinference/
[1] http://apps.gotdotnet.com/xmltools/xsdobjgen/
> -----Original Message-----
> From: Dino Chiesa [Microsoft] [mailto:dinoch@online.microsoft.com]
[quoted text clipped - 33 lines]
>
> C. the class I got by following the steps above was this:
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.abcinc.
co
> m/objectdefinition")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.abcinc.
co
> m/objectdefinition",
> IsNullable=false)]
[quoted text clipped - 76 lines]
> >
> > Mike
Mike Sarbu - 28 Dec 2004 03:46 GMT
Hi Dino,
Thanks a lot for the pointers you gave me, they were great. Unfortunately, I
still have problems.
Sorry for the missing quotes in the example that I posted, I typed it
instead of doing a copy-paste. In the real file the quotes were present.
Now about my issues:
1. The publisher (which is Microsoft) didn't publish the schema.
2. xsd.exe cannot infer the schema from the xml file because of an error in
the xml document: "The same table (somenamehere) cannot be the child table
in two nested relations". Now the xml file is generated by a Microsoft tool,
so I would've expected it to be correct ...
3. Even when I delete the offending elements, I can succesfully generate the
schema, I then generate the class, which looks identical to the one you've
generated, but I get the same error when deserializing it.
Thanks a lot for any other piece of advice that may help,
Mike
> Mike,
> to solve these sorts of problems, you can try working in the opposite
[quoted text clipped - 105 lines]
>>
>> Mike
Christoph Schittko [MVP] - 28 Dec 2004 04:15 GMT
Can you post what XML files your dealing with? You said that they are
generated by a Microsoft tool. Could you say which tool?
HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko
> -----Original Message-----
> From: Mike Sarbu [mailto:m_sarbu@yahoo.com]
[quoted text clipped - 68 lines]
> >
> > C. the class I got by following the steps above was this:
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.abcinc.
co
> m/objectdefinition")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.abcinc.
co
> m/objectdefinition",
> > IsNullable=false)]
[quoted text clipped - 76 lines]
> >>
> >> Mike