我有个xml格式文件,如下
<root>
<subnode name= "liu " url= "www.sina.com "> </subnode>
<subnode name= "huang " url= "www.sina.com "> </subnode>
<subnode name= "huang1 ' url= "www.sohu.com "> </subnode>
<subnode name= "huang2 ' url= "www.cctv.com "> </subnode>
</root>
请教如何判断该xml子节点是否存在 name=huang1的节点?
<root>
<subnode name= "liu " url= "www.sina.com "> </subnode>
<subnode name= "huang " url= "www.sina.com "> </subnode>
<subnode name= "huang1 ' url= "www.sohu.com "> </subnode>
<subnode name= "huang2 ' url= "www.cctv.com "> </subnode>
</root>
请教如何判断该xml子节点是否存在 name=huang1的节点?
uses msxml;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
const
XML = '<root>' +
' <subnode name= "liu" url= "www.sina.com "> </subnode>' +
' <subnode name= "huang" url= "www.sina.com "> </subnode>' +
' <subnode name= "huang1" url= "www.sohu.com "> </subnode>' +
' <subnode name= "huang2" url= "www.cctv.com "> </subnode>' +
' </root>';
var
XmlDoc: IXMLDOMDocument;
begin
XmlDoc := CoDOMDocument.Create; if XmlDoc.LoadXml(XML) then
begin
if XmlDoc.selectSingleNode('root/subnode[@name="huang1"]') <> nil then
ShowMessage('存在huang1'); if XmlDoc.selectSingleNode('root/subnode[@name="huang3"]') = nil then
ShowMessage('不存在huang3');
end;
end;
我正好收藏一下。很少用msxml啊