更新时间:2023-11-07 12:07:16
请记住,XML是节点的层次结构,包括文本片段.您显示的XML在树中看起来像这样:
Keep in mind that XML is a hierarchy of nodes, including text snippets. The XML you showed looks like this in a tree:
[element] 'text:p'
│
├─[attributes]
│ │
│ └─[attribute] 'text:style-name'
│ │
│ └─[text] 'PS'
│
└─[children]
|
├─[text] 'Prepared by: '
│
├─[element] 'text:tab'
│
└─[text] 'Tim Test'
这应该可以帮助您可视化如何将节点添加到文档中以获得所需的输出,例如:
That should help you visualize how you have to add nodes to your document to get the desired output, eg:
Node, Node1, Node2: IXMLNode;
...
Node := Node1.AddChild('text:p');
Node.Attributes['text:style-name'] := 'P5';
Node2 := Node.OwnerDocument.CreateNode('Prepared by: ', ntText);
Node.ChildNodes.Add(Node2);
Node2 := Node.OwnerDocument.CreateElement('text:tab', '');
Node.ChildNodes.Add(Node2);
Node2 := Node.OwnerDocument.CreateNode('Tim Test', ntText);
Node.ChildNodes.Add(Node2);