本文介绍了Delphi中的DOMElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在DOMNodeList对象中使用.getElementsByTagName?
喜欢:
how i can use .getElementsByTagName in DOMNodeList Object ? Like:
procedure TForm1.selecionarClick(Sender: TObject);
var DOMDocument: iXMLDOMDocument;
DOMNodeList: iXMLDOMNodeList;
DOMNode: iXMLDOMNode;
DOMElement: iXMLDOMElement;
i: Integer;
begin
Memo.Text := '';
with DOMDocument do
begin
DOMDocument := coDOMDocument.Create;
DOMDocument.load( 'C:\Usuarios.xml' );
DOMDocument.preserveWhiteSpace := false;
DOMNodeList := DOMDocument.selectNodes( './/usuario[@codigo="'+codigo.Text+'"]/' );
for i := 0 to DOMNodeList.length - 1 do
begin
end;
end;
end;
我的XML结构:
<?xml version="1.0" encoding="utf-8"?>
<usuarios>
<usuario codigo="1">
<nome>Name Node</nome>
<sobrenome>Last Name Node</sobrenome>
<cidade>City Node</cidade>
<estado>State Node</estado>
<email>Mail Node</email>
</usuario>
</usuarios>
推荐答案
GetElementsByTagName 不是 IXMLDOMNodeList 的成员,但是 IXMLDOMDocument 。在IXMLDOMNodeList上,要通过标签名称来抓取,您必须循环使用这种类型的结构:
GetElementsByTagName is not a member of IXMLDOMNodeList, but of IXMLDOMDocument. On IXMLDOMNodeList, to grab by tag name you must loop using this type of construct:
for i := 0 to DOMNodeList.length - 1 do
begin
DOMNode := DOMNodeList[i];
if DOMNode.nodeName = 'aTagName' then
DoStuff(DOMNode);
// etc etc....
end;
HTH
这篇关于Delphi中的DOMElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!