XML Serialization Question

M

Marcus de Leon

Hi,

I have a class that I am serializing like so:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="cds")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="cds",
IsNullable=false)]
public class MyOb1
{
[System.Xml.Serialization.XmlTypeAttribute
(Namespace="cds_dt")]
public class personName;
}


It serializes like so:
<MyOb1 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance" xmlns="cds">
<LegalName xmlns="cds_dt">

but I want is like this:
<MyOb1 xmlns:cds="cds" xmlns:cdsd="cds_dt"
xsi:schemaLocation="cds.xsd" xmlns="cds" xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance">
<cdsd:LegalName>


Can anybody point me to the right direction to do this. I am
using .NET 1.1

Thanks,

Marcus de Leon
 
M

Martin Honnen

Marcus said:
but I want is like this:
<MyOb1 xmlns:cds="cds" xmlns:cdsd="cds_dt"
xsi:schemaLocation="cds.xsd" xmlns="cds" xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance">
<cdsd:LegalName>


Can anybody point me to the right direction to do this. I am
using .NET 1.1

I am not sure it is available in .NET 1.1 but try whether you can use
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("cdsd", "cds_dt");

XmlSerializer ser = new XmlSerializer(typeof(MyOb1));
ser.Serialize(XmlWriter.Create("myObj.xml"), myObj1Instance, ns);
 
M

Martin Honnen

Marcus said:
but I want is like this:
<MyOb1 xmlns:cds="cds" xmlns:cdsd="cds_dt"
xsi:schemaLocation="cds.xsd" xmlns="cds" xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance">
<cdsd:LegalName>


Can anybody point me to the right direction to do this. I am
using .NET 1.1

I am not sure it is available in .NET 1.1 but try whether you can use
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("cdsd", "cds_dt");

XmlSerializer ser = new XmlSerializer(typeof(MyOb1));
ser.Serialize(XmlWriter.Create("myObj.xml"), myObj1Instance, ns);
 
M

Marcus de Leon

I am not sure it is available in .NET 1.1 but try whether you can use
   XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
   ns.Add("cdsd", "cds_dt");

   XmlSerializer ser = new XmlSerializer(typeof(MyOb1));
   ser.Serialize(XmlWriter.Create("myObj.xml"), myObj1Instance, ns);

Thanks! that worked. Another question, I am getting d1p1 instead of
xsi in some places. How can I correct this?

Thanks,

Marcus
 
M

Marcus de Leon

I am not sure it is available in .NET 1.1 but try whether you can use
   XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
   ns.Add("cdsd", "cds_dt");

   XmlSerializer ser = new XmlSerializer(typeof(MyOb1));
   ser.Serialize(XmlWriter.Create("myObj.xml"), myObj1Instance, ns);

Thanks! that worked. Another question, I am getting d1p1 instead of
xsi in some places. How can I correct this?

Thanks,

Marcus
 
M

Marcus de Leon

Try simply adding
       ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
to the XmlSerializerNamespaces object.

Another question...

I have a sub element:
<Contact d4p1:ContactPurpose="EC" xmlns:d4p1="cds">

but I need it to be
<Contact ns1:ContactPurpose="EC" xmlns:ns1="cds">

How do I assign the namespace down to this level?

Thanks,

Marcus
 
M

Marcus de Leon

Try simply adding
       ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
to the XmlSerializerNamespaces object.

Another question...

I have a sub element:
<Contact d4p1:ContactPurpose="EC" xmlns:d4p1="cds">

but I need it to be
<Contact ns1:ContactPurpose="EC" xmlns:ns1="cds">

How do I assign the namespace down to this level?

Thanks,

Marcus
 
M

Marcus de Leon

Another question...

I have a sub element:
 <Contact d4p1:ContactPurpose="EC" xmlns:d4p1="cds">

but I need it to be
 <Contact ns1:ContactPurpose="EC" xmlns:ns1="cds">

How do I assign the namespace down to this level?

Thanks,

Marcus

Does anybody know where the xmlns:d4p1 comes from?
 
M

Marcus de Leon

Another question...

I have a sub element:
 <Contact d4p1:ContactPurpose="EC" xmlns:d4p1="cds">

but I need it to be
 <Contact ns1:ContactPurpose="EC" xmlns:ns1="cds">

How do I assign the namespace down to this level?

Thanks,

Marcus

Does anybody know where the xmlns:d4p1 comes from?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top