xml serialize

S

Steph

hello,
just a little probleme...
how can i do, for delete "q1:" when i serialize my object ?


[Serializable]
[XmlRoot(ElementName="rr",Namespace = "http://www.mysite.com/ws/")]
public class header
{
private string f = "rr";
[XmlElement]
public string ff
{
set{f=value;}
get { return f;}
}
}



<?xml version="1.0" encoding="utf-16"?>
<q1:rr xmlns:q1="http://www.mysite.com/ws/">
<q1:ff>rr</q1:ff>
</q1:rr>


and i want :

<?xml version="1.0" encoding="utf-16"?>
<rr xmlns:q1="http://www.mysite.com/ws/">
<ff>rr</ff>
</rr>
 
M

Martin Honnen

Steph said:
[XmlRoot(ElementName="rr",Namespace = "http://www.mysite.com/ws/")]

You will have to decide what you want, if you specify the Namespace here
for the element then the serializer will use that namespace for the
element. If you don't want that, then don't use Namespace =
"http://www.mysite.com/ws/".

<?xml version="1.0" encoding="utf-16"?>
<rr xmlns:q1="http://www.mysite.com/ws/">
<ff>rr</ff>
</rr>

Then use

[XmlRoot(ElementName = "rr")]
public class header
{
private string f = "rr";
[XmlElement]
public string ff
{
set { f = value; }
get { return f; }
}
}

and

header h = new header();
XmlSerializer ser = new XmlSerializer(typeof(header));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("q1", "http://www.mysite.com/ws/");
ser.Serialize(Console.Out, h, ns);
 

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

Similar Threads

Serialize Class 6
q1 ??? 2
add header 2
XML Deserialization Question 2
XML Serialization 2
Deserialize case sensitive 7
XmlSerializer not creating attribute values 2
XML Encoding 2

Top