xml - 在 Delphi 中创建 OpenXML app.xml 已添加属性
问题描述
我正在.docx
用 Delphi 中的 OpenXML 创建一个文件。当我\docProps\app.xml
在 Delphi 中创建生成 docx 时,由于某种原因总是添加一个标签。
我要创建的 XML 文件是这样的:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<Template>Normal.dotm</Template>
<TotalTime>1</TotalTime>
<Pages>1</Pages>
<Words>1</Words>
...
</Properties>
通过做这个:
var
Root: IXMLNode;
Rel: IXMLNode;
Root := XMLDocument1.addChild('Properties');
... //attributes are added here
Rel := Root.AddChild('Template');
Rel.NodeValue := 'Normal.dotm';
Rel := Root.AddChild('TotalTime');
Rel.NodeValue := '1';
...
我期待上面的代码在顶部生成 XML 文件,但我得到了这个:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<Template xmlns="">Normal.dotm</Template >
<TotalTime xmlns=""></TotalTime>
<Pages xmlns="">1</Pages>
</Properties>
xmlns
由于某种原因添加了该属性。有没有办法在顶部实现预期的 XML?
解决方案
创建元素时显式提供命名空间 URI:
const
PROP_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties';
var
Root: IXMLNode;
Rel: IXMLNode;
Root := XMLDocument1.AddChild('Properties', PROP_NS);
Rel := Root.AddChild('Template', PROP_NS);
Rel.NodeValue := 'Normal.dotm';
Rel := Root.AddChild('Pages', PROP_NS);
Rel.NodeValue := '1';
推荐阅读
- angular - 带有导航栏的 Angular 登录页面 - 事件顺序问题
- c - 如何在 Visual Studio 代码中为特定功能启用完美和完整的智能感知
- python - 如何在下面的代码中实现 DFS?
- curl - 在 Docker 构建中运行 cURL 命令
- python - django 中的 check_password() 总是返回 false
- php - 如何在sql中的多个字段上使用group by语句?
- python - 通过在列表中的字符串子字符串中搜索数据来填充熊猫数据框
- ubuntu - 无法在 Ubuntu 20.04 上安装 ROS Melodic
- python - 使用 SNAP 库构建加权无向图
- laravel - Laravel:存储链接返回无效的 url