要求:
我似乎无法从谷歌搜索到这一点.有没有人用过类似的东西?
我正在使用C#,它需要在Windows,Linux和Mac上运行,后两者需要使用Mono.
我可能愿意使用p/invoke,但我对本机代码并不是特别熟悉,而且很难.如果有人可以建议一个本地图书馆,我会试一试.
使用Mono版本2.10.5,以下代码在任何XML文档上都失败:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Xml.Linq;
namespace TestXDocument
{
class MainClass
{
public static void Main (string[] args)
{
Stream s = File.Open("Settings.xml", FileMode.Open);
XDocument d = XDocument.Load(s, LoadOptions.PreserveWhitespace);
s.Close();
d.Save("Settings.xml");
}
}
}
Run Code Online (Sandbox Code Playgroud)
只有在XDocument.Load使用LoadOptions.PreserveWhitespace时才会发生这种情况.有关如何解决这个问题或解决问题的任何想法?
在Linux Mint 12和Ubuntu 11.10上测试过.
这是例外:
Unhandled Exception: System.InvalidOperationException: This XmlWriter does not accept Text at this state Prolog.
at System.Xml.XmlTextWriter.ShiftStateContent (System.String occured, Boolean allowAttribute) [0x00000] in <filename unknown>:0
at System.Xml.XmlTextWriter.WriteString (System.String text) [0x00000] in <filename unknown>:0
at System.Xml.DefaultXmlWriter.WriteString (System.String text) …
Run Code Online (Sandbox Code Playgroud)