T
Tom
This is probably easy, but I have spent several hours trying to get it to
work with no luck.
I'm just using the XmlSerializer class to write an XML file:
XmlSerializer s = new XmlSerializer(typeof(myType));;
XmlSerializerNamespaces n = new XmlSerializerNamespaces();
n.Add(string.Empy, string.Empy);
Stream fs = new FileStream(name, FileMode.Create);
XmlTextWriter tw = new XmlTextWriter(fs, Encoding.UTF8);
tw.Formatting = Formatting.None;
s.Serialize(tw, myObject, n);
tw.Close();
Anyway, the above works almost to what I want, but it produces the following
XML file:
<?xml version="1.0" encoding="utf-8" ?>
<q1:myObjElement1 xmlns:q1="myXSD.xsd">
<MyElement2>
<MyElement3>
</MyElement3>
</MyElement2>
</q1:myObjeElement1>
My problem is that I want to get rid of that "q1:" string, and just
serialize my object into XML. What is the "q1:" string anyway, and why is
it there?
I can get rid of the "q1:" string by changing the following attribute in my
code from:
[System.Xml.Serialization.XmlRootAttribute(IsNullable = false,
Namespace="myXSD.xsd")];
to:
[System.Xml.Serialization.XmlRootAttribute(IsNullable = false)];
However, if I do that, then I get:
<?xml version="1.0" encoding="utf-8" ?>
<myObjElement1>
<MyElement2>
<MyElement3>
</MyElement3>
</MyElement2>
</myObjeElement1>
The problem here is that I need the line:
<myObjElement1>
to really read:
<myObjElement1 xmlns="myXSD.xsd">
So in short:
How can I get rid of the "q1:" string and keep the xmlns attribute in my
root element?
Thank you.
work with no luck.
I'm just using the XmlSerializer class to write an XML file:
XmlSerializer s = new XmlSerializer(typeof(myType));;
XmlSerializerNamespaces n = new XmlSerializerNamespaces();
n.Add(string.Empy, string.Empy);
Stream fs = new FileStream(name, FileMode.Create);
XmlTextWriter tw = new XmlTextWriter(fs, Encoding.UTF8);
tw.Formatting = Formatting.None;
s.Serialize(tw, myObject, n);
tw.Close();
Anyway, the above works almost to what I want, but it produces the following
XML file:
<?xml version="1.0" encoding="utf-8" ?>
<q1:myObjElement1 xmlns:q1="myXSD.xsd">
<MyElement2>
<MyElement3>
</MyElement3>
</MyElement2>
</q1:myObjeElement1>
My problem is that I want to get rid of that "q1:" string, and just
serialize my object into XML. What is the "q1:" string anyway, and why is
it there?
I can get rid of the "q1:" string by changing the following attribute in my
code from:
[System.Xml.Serialization.XmlRootAttribute(IsNullable = false,
Namespace="myXSD.xsd")];
to:
[System.Xml.Serialization.XmlRootAttribute(IsNullable = false)];
However, if I do that, then I get:
<?xml version="1.0" encoding="utf-8" ?>
<myObjElement1>
<MyElement2>
<MyElement3>
</MyElement3>
</MyElement2>
</myObjeElement1>
The problem here is that I need the line:
<myObjElement1>
to really read:
<myObjElement1 xmlns="myXSD.xsd">
So in short:
How can I get rid of the "q1:" string and keep the xmlns attribute in my
root element?
Thank you.