Delphi 中的 DOMElement
我如何在 DOMNodeList 对象中使用 .getElementsByTagName ? 比如:
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>
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;
My XML structure:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GetElementsByTagName 不是 IXMLDOMNodeList 的成员,而是 IXMLDOMDocument 的成员。在 IXMLDOMNodeList 上,要按标签名称抓取,您必须使用这种类型的构造进行循环:
HTH
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:
HTH
IDOMElement 支持 getElementsByTagName,它返回 IDOMNodeList。 IDOMElement 是 IDOMNode 的“子类”。
希望有帮助。 :)
IDOMElement supports getElementsByTagName which returns an IDOMNodeList. IDOMElement is a "subclass" of IDOMNode.
Hope that helps. :)