Search code examples
c++xmlc++builderxmldocument

Unwanted xmlns="" in _di_IXMLNode


I'm creating a xml-file for display in Excel using _di_IXMLDocument. But for some tags I get an unwanted extra (empty) xmlns attribute witch makes the file unreadable for Excel... This is what i do:

...
_di_IXMLNode worksheet = workbook->AddChild("Worksheet");
worksheet->SetAttribute("ss:Name",Now().DateString());
...

and this is what comes out:

<Worksheet xmlns="" ss:Name="2008-12-11">

Where does xmlns come from? How do I get rid of it?

EDIT: Some more info: If I try to add a xmlns attribute to Worksheet myself, like this:

...
_di_IXMLNode worksheet = workbook->AddChild("Worksheet");
worksheet->SetAttribute("xlmns","Foo");
worksheet->SetAttribute("ss:Name",Now().DateString());
...

Then the child nodes of "Worksheet" all get the empty xmlns attributes instead!

<Worksheet xmlns="Foo" ss:Name="2008-12-11">
  <Table xmlns="">

Solution

  • Ok I had a look at this question. The trick was to create the child nodes and telling the what namespace they belong to, and then not to output it...

    _di_IXMLNode worksheet = workbook->AddChild("Worksheet","workbooks-namespace",false);
    worksheet->SetAttribute("ss:Name",Now().DateString());
    

    this produces the desired output:

    <Worksheet ss:Name="2008-12-11">