xml文件中有命名空间:
xsi:schemaLocation='xsdHeadCount HeadCount.xsd'
在输出格式化xml流时会报“对空命名空间不能使用前缀。”错误信息。
请问怎么解决??????我不想输出文件再读出来。
------代码-----
XmlDocument doc=new XmlDocument();
....从对象生成XmlDocument.......
MemoryStream stream=new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(stream,null);
writer.Formatting = Formatting.Indented;//格式化类型
doc.Save(writer);//有xsi:schemaLocation就会报错,
writer.Flush();
byte[] b=stream.GetBuffer();
writer.Close();
stream.Close();
return Encoding.UTF8.GetString(b,0,b.Length);
xsi:schemaLocation='xsdHeadCount HeadCount.xsd'
在输出格式化xml流时会报“对空命名空间不能使用前缀。”错误信息。
请问怎么解决??????我不想输出文件再读出来。
------代码-----
XmlDocument doc=new XmlDocument();
....从对象生成XmlDocument.......
MemoryStream stream=new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(stream,null);
writer.Formatting = Formatting.Indented;//格式化类型
doc.Save(writer);//有xsi:schemaLocation就会报错,
writer.Flush();
byte[] b=stream.GetBuffer();
writer.Close();
stream.Close();
return Encoding.UTF8.GetString(b,0,b.Length);
请大家帮帮我!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<?xml version="1.0" encoding="us-ascii"?>
<Package xmlns="http://www.wfmc.org/2002/XPDL1.0" xmlns:xpdl="http://www.wfmc.org/2002/XPDL1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xyz="http://www.xyzeorder.com/workflow" xsi:schemaLocation="http://www.wfmc.org/2002/XPDL1.0 http://wfmc.org/standards/docs/TC-1025_schema_10_xpdl.xsd" Id="0" Name="sample workflow process">
....
</Package>
<Package xmlns="http://www.wfmc.org/2002/XPDL1.0" xmlns:xpdl="http://www.wfmc.org/2002/XPDL1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xyz="http://www.xyzeorder.com/workflow" xsi:schemaLocation="http://www.wfmc.org/2002/XPDL1.0 http://wfmc.org/standards/docs/TC-1025_schema_10_xpdl.xsd" Id="0" Name="sample workflow process">
这些都写在了文件里面,然后用xmldocument读取进行编辑,编辑的过程中注意命名空间的问题,例如:
XmlNamespaceManager nsmgr = new XmlNamespaceManager(YourXmlDocument.NameTable);
nsmgr.AddNamespace("xpdl", "http://www.wfmc.org/2002/XPDL1.0");
XmlAttribute attr = YourXmlDocument.CreateAttribute(xpath);
这样再次保存的时候就不会有错误提示,并且格式十分标准,没有空命名空间的现象出现,具体原因还不是很清楚,做完之后也没有仔细的研究,建议你也这么试试