xmlを読み込もうとすると、「予期しないXML宣言。XML宣言はドキュメントの最初のノードである必要があり、その前に空白文字を表示することはできません」というエラーが表示されます。私のC#コードとXMLファイルの内容の両方を以下に示します。XML定義がxmlファイルの6行目に存在するため、エラーが発生します。
xmlファイルの内容を制御できないので、C#を使用して編集/書き換えて、xml宣言が最初に来て、次にコメントがエラーなしでロードされるようにするにはどうすればよいですか?
//xmlFilepath is the path/name of the xml file passed to this function
static function(string xmlFilepath)
{
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.IgnoreComments = true;
readerSettings.IgnoreWhitespace = true;
XmlReader reader = XmlReader.Create(XmlFilePath, readerSettings);
XmlDocument xml = new XmlDocument();
xml.Load(reader);
}
XmlDoc.xml
<!-- Customer ID: 1 -->
<!-- Import file: XmlDoc.xml -->
<!-- Start time: 8/14/12 3:15 AM -->
<!-- End time: 8/14/12 3:18 AM -->
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
-----