views:

272

answers:

2

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="">
A: 

xmlns stands for xml name space, if an attribute does not receive an explicit name space, it possesses none.

http://www.w3.org/TR/REC-xml-names/

Edouard A.
Thanks, but not really answering my question...
c0m4
A: 

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">
c0m4