"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote:
But there's still a problem. The elements below this element
doesn't recognize the attributes, so the namespace declarations are
repated for each element. Is there a solution for this too?
Most likely you are doing something wrong. You are not supposed to
create namespace declarations by hands, that's XmlWriter's
responsibility.
Thank you both. What complicates my problem is that I need to import a
chunk of XML from an existing document, into a document that I
generate dynamically. Here's the code for extracting the chunk:
XmlDocument d = new XmlDocument();
d.Load(file_document);
XmlNodeList nl =
d.DocumentElement.GetElementsByTagName("GeneralDoc umentInformation",
NS_XBRL);
And here is the document that is being generated:
// Create XmlTextWriter
XmlTextWriter w = new XmlTextWriter("output.xml",
System.Text.Encoding.UTF8);
w.Formatting = Formatting.Indented;
w.Indentation = 2;
w.WriteStartDocument();
w.WriteStartElement("xbrl", NS_XBRL);
w.WriteAttributeString("xmlns:int", NS_INT);
w.WriteAttributeString("xmlns:bas", NS_BAS);
w.WriteRaw(nl.Item(0).OuterXml);
The chunk that is imported looks like this:
<GeneralDocumentInformation>
<int:DocumentLastEditDate>1995-09-25</int:DocumentLastEditDate>
<int:EntityCurrentLegalNameName />
<int:EntityIdentifier>
<int:EntityIdentifierDescription>50020</int:EntityIdentifierDescriptio
n>
</int:EntityIdentifier>
<int:EntityTradingName />
<bas:LocalAddress>
<int:Street1>Gångstigen 4</int:Street1>
</bas:LocalAddress>
<bas:ZIPPostalCode>414 65</bas:ZIPPostalCode>
<int:City>GÖTEBORG</int:City>
<bas:PhoneFaxNumbers>
<bas:Phone />
</bas:PhoneFaxNumbers>
</GeneralDocumentInformation>
And this is the result I get (removed the URIs for readability):
<?xml version="1.0" encoding="utf-8"?>
<xbrl xmlns:int="..." xmlns:bas="..." xmlns="...">
<GeneralDocumentInformation xmlns="...">
<int:DocumentLastEditDate xmlns:int="...">
1995-09-25
</int:DocumentLastEditDate>
<int:EntityCurrentLegalNameName xmlns:int="..." />
<int:EntityIdentifier xmlns:int="...">
<int:EntityIdentifierDescription>
50020
</int:EntityIdentifierDescription>
</int:EntityIdentifier>
<int:EntityTradingName xmlns:int="..." />
<bas:LocalAddress xmlns:bas="...">
<int:Street1 xmlns:int="...">Gångstigen 4</int:Street1>
</bas:LocalAddress>
<bas:ZIPPostalCode xmlns:bas="...">414 65</bas:ZIPPostalCode>
<int:City xmlns:int="...">GÖTEBORG</int:City>
<bas:PhoneFaxNumbers xmlns:bas="...">
<bas:Phone />
</bas:PhoneFaxNumbers>
</GeneralDocumentInformation>
</xbrl>
Thanks a lot for help.
Gustaf