I have the following xml.
The namespaces are very broken up, but the xml itself is valid. Is there any way to configure a writer to output this xml with all the relevant namespaces at the top, and the xml cleaner? My xml reader / writer combinations seems to be faithfully reproducing this. I would rather have all the namespaces consolidated.
I don’t really rather not use xslt if possible.
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:a="http://www.w3.org/2005/Atom/extensions/property" a:length="1">
<title type="text">Search Results: '80706'</title>
<subtitle type="text">search results</subtitle>
<id>80706</id>
<updated>2011-08-30T09:05:21+02:00</updated>
<author>
<name>XXXXXX</name>
<uri>contact@xxxx</uri>
<email>contact@xxxx.com</email>
</author>
<entry">
<id>8000</id>
<title type="text">Investment 0000000</title>
<summary type="text">pre populated form</summary>
<published>2011-08-30T14:57:45Z</published>
<updated>2011-08-30T09:05:21+02:00</updated>
<content type="application/xml">
<prop:query-result xmlns:prop="http://www.w3.org/2005/Atom/extensions/property" xmlns="http://www.w3.org/2005/Atom/extensions/property">
<prop:PartyId>000000</prop:PartyId>
<prop:IDReferenceNumber>000000</prop:IDReferenceNumber>
<prop:FullName></prop:FullName>
<prop:FirstName>FIRST</prop:FirstName>
<prop:LastName>LAST</prop:LastName>
<prop:Title>Mr</prop:Title>
<prop:BirthDate>1967-05-24T00:00:00</prop:BirthDate>
<prop:PartySystemKey source="Number">000000</prop:PartySystemKey>
<prop:Address type="Mailing">BOX ...</prop:Address>
<prop:Address type="Home">39 ...</prop:Address>
<prop:ContactNumber>0000000</prop:ContactNumber>
<prop:InvestmentNumber source="ContractNumber">0000000</prop:InvestmentNumber>
<prop:InvestmentNumber source="AccountNumber">0000000</prop:InvestmentNumber>
</prop:query-result>
</content>
</entry>
</feed>
Well, XmlReader works forwards only so finding used namespaces anywhere to put them on the root is somehow difficult with an XmlReader/Writer combination.
You could however try LINQ to XML, when I run the code (.NET 4.0)
against the sample input
I get the output
Does that suffice? You haven’t said what kind of result you want and whether there are input variants where namespaces are used down some levels that are not declared earlier that need to be lifted up. With your current sample it suffices to simply remove duplicated namespace declarations.