我在字符串var" xml"
中有xml<?xml version=""1.1"" encoding=""UTF - 8"" ?>
< insertCommand table=""Colors"">
<parameter name=""Color"">Red</parameter>
<parameter name=""Code"">#FF0000</parameter>
</insertCommand>
我尝试获取XDocument。
using (var inputStream = new StringReader(xml))
{
//var doc = new XPathDocument(inputStream);// It`s a same result
var doc = XDocument.Load(inputStream); // the exception occurs
using (var outputStream = doc.CreateWriter())
{
....
}
}
System.Xml.XmlException。不允许使用版本号1.1。
答案 0 :(得分:1)
除非XML中有特定于1.1的内容,否则您可以将其作为字符串读取,将版本更改为1.0,然后正常处理。您可以进行网络搜索以找出差异。
在VB .Net中这很有用
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
path = IO.Path.Combine(path, "test.xml")
Dim myXML As String = IO.File.ReadAllText(path)
Dim repl As String = "<?xml version=""1.1"""
Dim replwith As String = "<?xml version=""1.0"""
myXML = myXML.Replace(repl, replwith)
Dim xe As XElement = XElement.Parse(myXML)
FWIW - 你发布的xml有一些错误
<?xml version=""1.1"" encoding="utf-8" ?> encoding attribute
<insertCommand table=""Colors""> spce before tag name
<parameter name=""Color"">Red</parameter>
<parameter name=""Code"">#FF0000</parameter>
</insertCommand>