开发者

Get pure XML from Object

I have following code which converts Object into XML and it working fine.

    public static string ConvertObjectToXML(Object obj)
    {
        String XmlizedString = null;
        MemoryStream memoryStream = new MemoryStream();
        XmlSerializer xs = null;

            if (obj is DerivedClass2)
            {
                xs = new XmlSerializer(typeof(DerivedClass2));
            }

        TextWriter w = new StringWriter();
        //this.s = new XmlSerializer(this.type);
        xs.Serialize(w, notoficationOrder);
        w.Flush();
        //return w;
        XmlizedString = w.ToStr开发者_C百科ing();
        w.Close();
        return XmlizedString.Trim();
   }

And it gives following output

<?xml version="1.0" encoding="utf-16"?>*   
<Obj xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <List>
        <!--...-->
    </List>
</Obj>

But I do not want XML which depicts Xml Namespace xd etc. I need only pure Object output of as below

<Obj>
  <List>
     <!--...-->
  </List>
</Obj>

Thanks

Ocean


How to PROPERLY remove xmln:xsi and xmlns:xsd from xml dictionary serialization

This is VB .NET but the idea is the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜