我遇到問題。我寫了一個程序,將大量的數據轉換爲VML-GML
格式。問題是我需要使用XmlWriter
...現在我有一個問題,我下面的方法:XmlWriter使命名空間不正確
private void StartDocument()
{
_writer.WriteStartDocument();
_writer.WriteStartElement("osgb", "FeatureCollection", "osgb");
_writer.WriteAttributeString("osgb", "xmlns", "http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1");
_writer.WriteAttributeString("gml", "xmlns", "http://www.opengis.net/gml");
_writer.WriteAttributeString("xsi", "xmlns", "http://www.w3.org/2001/XMLSchema-instance");
_writer.WriteAttributeString("schemaLocation", "xsi",
"http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1 http://www.ordnancesurvey.co.uk/oswebsite/xml/cmdschema/local/V1.1/CMDFeatures.xsd");
_writer.WriteAttributeString("fid", ""); // TODO: set fid here
_writer.WriteStartElement("gml", "description", "gml");
_writer.WriteValue("Ordnance Survey, (c) Crown Copyright. All rights reserved, 2011-03-02");
_writer.WriteEndElement(); // description
_writer.WriteElementString("osgb", "creationDate", "osgb", DateTime.Today.ToString("yyyy-MM-dd"));
}
如何在正確的命名空間寫?我這樣做那樣,輸出是:
<?xml version="1.0" encoding="utf-8"?>
<osgb:FeatureCollection p1:osgb="http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1"
p1:gml="http://www.opengis.net/gml"
p1:xsi="http://www.w3.org/2001/XMLSchema-instance"
p2:schemaLocation="http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1 http://www.ordnancesurvey.co.uk/oswebsite/xml/cmdschema/local/V1.1/CMDFeatures.xsd"
fid="" xmlns:p2="xsi" xmlns:p1="xmlns" xmlns:osgb="osgb">
而這正是我需要的:
<osgb:FeatureCollection xmlns:osgb="http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1 http://www.ordnancesurvey.co.uk/oswebsite/xml/cmdschema/local/V1.1/CMDFeatures.xsd"
fid="">
爲什麼會這樣愚蠢XmlWriter
創造一個像p1
,p2
等這樣的事情?
Btw。我試圖在使用這些VML-GML
文件的程序中打開我的輸出文件,並告訴我該文件格式不正確。當我手動將名稱空間更改爲正確的名稱空間時,一切都很好。
如何糾正它?提前致謝!
的CuzüR值不要使用linq2Xml – Anirudha
我,因爲大量的數據不是。 – Nickon
linq2xml可以處理..沒有問題在它..它是一個完全替代其他XML API .. – Anirudha