Note that there are some explanatory texts on larger screens.

plurals
  1. POXmlWriter makes not correct namespaces
    text
    copied!<p>I have a problem. I wrote a program that converts some large amount of data into <code>VML-GML</code> format. The problem is I need to use <code>XmlWriter</code>... Now I have a problem with my method below:</p> <pre><code>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")); } </code></pre> <p>How to write in namespaces correctly? I did this in that way and the output is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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"&gt; </code></pre> <p>And this is what I need:</p> <pre><code>&lt;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=""&gt; </code></pre> <p>Why is that stupid <code>XmlWriter</code> creating such things like <code>p1</code>, <code>p2</code>, etc.?</p> <p>Btw. I tried to open my output file in the program that uses those <code>VML-GML</code> files and it told me that the file is in a bad format. When I manually changed namespaces into the correct ones, everything was great.</p> <p>How to correct it? Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload