gpt4 book ai didi

xml - 提取 XML 中的值

转载 作者:数据小太阳 更新时间:2023-10-29 02:24:07 24 4
gpt4 key购买 nike

我需要解析以下 XML:

<?xml version="1.0" encoding="UTF-8" ?>
<revista numero="2226" data="03/09/2013">
<processo numero="902987089">
<despachos>
<despacho codigo="IPAS139"/>
</despachos>
<titulares>
<titular nome-razao-social="AAAAA" pais="BR" uf="PR"/>
</titulares>
</processo>
<processo numero="902812165">
<despachos>
<despacho codigo="IPAS029"/>
</despachos>
<titulares>
<titular nome-razao-social="XXXX" pais="BR" uf="SC"/>
</titulares>
(...)

我对 XML 一点经验都没有。我正在使用 IXMLDocument在德尔福。

LNodeElement := LDocument.ChildNodes.FindNode('revista');
(...)
for I := 0 to LNodeElement.ChildNodes.Count - 1 do
(...)

我的问题是如何到达 numero <processo> 里面的属性值标签?但如果好心人可以分享一个小例子,我们将不胜感激。

最佳答案

比如这样:

uses
XMLDoc, XMLIntf;

procedure TForm3.Button1Click(Sender: TObject);
var
I: Integer;
NumberAttr: IXMLNode;
XMLDocument: IXMLDocument;
ProcessNodes: IXMLNodeList;
begin
// load an XML file
XMLDocument := LoadXMLDocument('c:\File.xml');
// take the list of all "revista/processo" nodes
ProcessNodes := XMLDocument.DocumentElement.ChildNodes;
// and iterate that "processo" node collection
for I := 0 to ProcessNodes.Count - 1 do
begin
// try to find the "numero" attribute for currently iterated "processo" node
NumberAttr := ProcessNodes[I].AttributeNodes.FindNode('numero');
// if the "numero" attribute was found, show its value (or do something else)
if Assigned(NumberAttr) then
ShowMessage(NumberAttr.Text);
end;
end;

关于xml - 提取 XML 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18635770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com