Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Why is that stupid XmlWriter creating such things like p1, p2, etc.?</p> </blockquote> <p>You've got your attribute values the wrong way round, and you also need to specify another argument:</p> <p>This:</p> <pre><code>_writer.WriteAttributeString("gml", "xmlns", "http://www.opengis.net/gml"); </code></pre> <p>should be this:</p> <pre><code>_writer.WriteAttributeString("xmlns", "gml", null, "http://www.opengis.net/gml"); </code></pre> <p>Additionally, your element writing code is incorrect. You're specifying the prefix when you should be specifying the namespace URI.</p> <p>I believe this does what you need:</p> <pre><code>_writer.WriteStartDocument(); // The first argument here isn't really needed, but is changes whether a // prefix is used or not _writer.WriteStartElement("osgb", "FeatureCollection", "http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1"); _writer.WriteAttributeString("xmlns", "osgb", null, "http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1"); _writer.WriteAttributeString("xmlns", "gml", null, "http://www.opengis.net/gml"); _writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); _writer.WriteAttributeString("schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "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("description", "http://www.opengis.net/gml"); _writer.WriteValue("Ordnance Survey, (c) Crown Copyright. All rights reserved, 2011-03-02"); _writer.WriteEndElement(); // description _writer.WriteElementString("creationDate", "http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1", DateTime.Today.ToString("yyyy-MM-dd")); _writer.WriteEndElement(); </code></pre> <p>(Personally I would use LINQ to XML, which makes all of this <em>much</em> simpler, but hey...)</p> <p>As a hint, always assume that <em>your</em> code is wrong rather than the framework code, as a starting point. Regarding a framework class as "stupid" is likely to lead to you not looking at your own code with sufficient care.</p> <p>EDIT: Here's working LINQ to XML code:</p> <pre><code>using System; using System.Xml.Linq; static class Test { static void Main() { XNamespace osgb = "http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1"; XNamespace gml = "http://www.opengis.net/gml"; XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; var doc = new XDocument( new XElement(osgb + "FeatureCollection", new XAttribute(XNamespace.Xmlns + "osgb", osgb), new XAttribute(XNamespace.Xmlns + "gml", gml), new XAttribute(XNamespace.Xmlns + "xsi", xsi), new XAttribute(xsi + "schemaLocation", "http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1 http://www.ordnancesurvey.co.uk/oswebsite/xml/cmdschema/local/V1.1/CMDFeatures.xsd"), new XAttribute("fid", ""), new XElement(gml + "description", "Ordnance Survey ..."), new XElement(osgb + "creationDate", // TODO: Find a better way of doing this DateTime.Today.ToString("yyyy-MM-dd")))); Console.WriteLine(doc); } } </code></pre> <p>Output:</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; &lt;gml:description&gt;Ordnance Survey ...&lt;/gml:description&gt; &lt;osgb:creationDate&gt;2012-10-19&lt;/osgb:creationDate&gt; &lt;/osgb:FeatureCollection&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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