我正在用Delphi中的OpenXML創建一個.docx檔案。當我在Delphi中創建docPropsapp.xml來生成docx時,由于某些原因,總是會添加一個標簽。
我想要創建的XML檔案是這樣的:
<?xml version="1.0" encoding="UTF-8" standalone="yes"? >/span>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"/span>
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<Template>Normal.dotm</Template>
<TotalTime>1</TotalTime>/span>
<Pages>1</Pages>/span>
<Words>1</Words>
...
</Properties> ...
通過這樣做:
var
根:IXMLNode。
Rel: IXMLNode;
Root := XMLDocument1.addChild('Properties')。
... //屬性被添加到這里。
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"? >/span>
<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>/span>
</Properties>/span>
xmlns屬性由于某種原因被添加。有什么方法可以在頂部實作預期的XML嗎?
uj5u.com熱心網友回復:
當你創建元素時,明確地提供命名空間URI:
span class="hljs-keyword">const
PROP_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties'。
var
根: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';
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/316512.html
標籤:
