在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文件? 展开
<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文件? 展开
1个回答
展开全部
如下
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的版本申明
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询