title: .net XMLSerializer multiple namespace problem
body: <p>I've got a problem using the .net XMLSerializer object and XML namespaces. My experience of the the XMLSerializer is very limited and I haven't worked with XML much before. I'm trying to something like the following:</p>
  
  <pre><code>&lt;Record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; 
    &lt;Property1&gt;blah&lt;/Property1&gt; 
    &lt;oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"   xmlns:dc="http://purl.org/dc/elements/1.1/"&gt;&gt;
      &lt;dc:Property2&gt;asdsd&lt;/dc:Property2&gt; 
      &lt;dc:Property3&gt;asdasasdda&lt;/dc:Property3&gt; 
    &lt;/oai_dc:dc&gt;
  &lt;/Record&gt;
  </code></pre>
  
  <p>however the best I can get at the moment is (note the position of the namespace declarations)</p>
  
  <pre><code>&lt;Record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/"&gt;
    &lt;Property1&gt;blah&lt;/Property1&gt; 
      &lt;oai_dc:dc&gt;
        &lt;dc:Property2&gt;asdsd&lt;/dc:Property2&gt; 
        &lt;dc:Property3&gt;asdasasdda&lt;/dc:Property3&gt; 
    &lt;/oai_dc:dc&gt;
  &lt;/Record&gt;
  </code></pre>
  
  <p>The namespaces are being declared in the root element, not on the dc element as I would like. I understand from that either declaring the namespace in the root or the element that uses the namespace should be acceptable.</p>
  
  <p>I'm attaching the XMLSerializerNamespaces as follows:</p>
  
  <pre><code>Dim XMLNamespaces As New XmlSerializerNamespaces()
          XMLNamespaces.Add("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/")
          XMLNamespaces.Add("dc", "http://purl.org/dc/elements/1.1/")
          XMLNamespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance")
  
  XMLSerializer.Serialize(XMLWriter, inputObject, XMLNamespaces)
  </code></pre>
  
  <p>and the objects I'm using are shown below:</p>
  
  <pre><code>&lt;XmlRoot("Record")&gt; _
  Public Class Record
  
      &lt;XmlElement("Property1")&gt; _
      Public Property1 As String
  
      &lt;XmlElement("dc", Namespace:="http://www.openarchives.org/OAI/2.0/oai_dc/")&gt; _
      Public DCMetadata As DublinCore
  
      Public Sub New()
          DCMetadata = New DublinCore()
      End Sub
  
  End Class
  
  
  &lt;XmlRoot("dc", Namespace:="http://www.openarchives.org/OAI/2.0/oai_dc/")&gt; _
  Public Class DublinCore
  
      &lt;XmlElement("Property2", Namespace:="http://purl.org/dc/elements/1.1/")&gt; _
      Public Property2 As String
  
      &lt;XmlElement("Property3", Namespace:="http://purl.org/dc/elements/1.1/")&gt; _
      Public Property3 As String
  
      Public Sub New()
  
      End Sub
  
  End Class
  </code></pre>
  
  <p>Is there any way to force the XMLSerializer to output the namespace declarations against an element further down the tree?</p>
  
  <p>Thanks for any input,</p>
  
  <p>Andy </p>