在xml中添加序列化对象时如何屏蔽头属性 <?xml version="1.0" encoding="UTF-8"?>

<?xmlversion="1.0"encoding="UTF-8"?><javaversion="1.5.0_11"class="java.beans.XMLDecod... <?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_11" class="java.beans.XMLDecoder">
<object class="test.Student">
<void property="address">
<string>4</string>
</void>
<void property="age">
<int>3</int>
</void>
<void property="birthdate">
<object class="java.util.Date">
<long>1273463850656</long>
</object>
</void>
<void property="delflag">
<byte>6</byte>
</void>
<void property="id">
<string>1</string>
</void>
<void property="name">
<string>2</string>
</void>
<void property="sortorder">
<int>5</int>
</void>
</object>
</java>
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_14" class="java.beans.XMLDecoder">
<object class="test.Student">
<void property="address">
<string>4</string>
</void>
<void property="age">
<int>3</int>
</void>
<void property="birthdate">
<object class="java.util.Date">
<long>1273463916687</long>
</object>
</void>
<void property="delflag">
<byte>6</byte>
</void>
<void property="id">
<string>1</string>
</void>
<void property="name">
<string>2</string>
</void>
<void property="sortorder">
<int>5</int>
</void>
</object>
</java>

在每次添加一个对象的时候都会出现 :

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_11" class="java.beans.XMLDecoder">

如何不让这个头插入到xml文件?
展开
 我来答
百度网友7467779
推荐于2018-04-05 · TA获得超过890个赞
知道小有建树答主
回答量:146
采纳率:100%
帮助的人:87.2万
展开全部

如下

                XmlTextWriter xmlWriter = new XmlTextWriter(filename,null);//不添加utf-8 BOM

                xmlWriter.Formatting = Formatting.Indented;

                // This will output the XML declaration
                xmlWriter.WriteStartDocument(true);//添加standalone="yes"
                //xmlWriter.Formatting = Formatting.None;//这句让xml失去任何缩进等格式

                xmlWriter.WriteStartElement("DocumentElement");


                    xmlWriter.WriteStartElement("Table");
                    //xmlWriter.WriteAttributeString("id", "01");//添加之后类似于<routeTable id="01"...
                    xmlWriter.WriteElementString("Att1","value1");
                    xmlWriter.WriteElementString("Att2","value2");
                    xmlWriter.WriteEndElement();
                xmlWriter.WriteEndDocument();
                xmlWriter.Close();

这样下来就是不带utf-8的,如果不添加下面这句xmlWriter.WriteStartDocument(true);//添加standalone="yes",那么文件头只有一个xml1.0的版本申明

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式