不需要的 xmlns="" 在 _di_IXMLNode 中

发布于 2024-07-11 07:09:23 字数 782 浏览 5 评论 0 原文

我正在使用 _di_IXMLDocument 创建一个用于在 Excel 中显示的 xml 文件。 但对于某些标签,我得到了一个不需要的额外(空)xmlns 属性,这使得 Excel 无法读取该文件... 这就是我所做的:

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

这就是结果:

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

xmlns 来自哪里? 我该如何摆脱它?

编辑: 更多信息:如果我尝试自己向工作表添加 xmlns 属性,如下所示:

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

那么“工作表”的子节点都会获得空的 xmlns 属性!

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小糖芽 2024-07-18 07:09:23

xmlns 代表 xml 名称空间,如果属性没有接收显式名称空间,则它不拥有任何名称空间。

http://www.w3.org/TR/REC-xml-names/< /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/

琉璃梦幻 2024-07-18 07:09:23

好的,我查看了这个 问题。 诀窍是创建子节点并告诉它们属于哪个名称空间,然后不输出它......

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

这会产生所需的输出:

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

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">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文