Monday, 15 August 2011

How does it work XPath in delphi? -



How does it work XPath in delphi? -

this xml file (content.xml):

class="lang-xml prettyprint-override"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head></head> <body> <h1>lorem ipsum dolor sit down amet</h1> </body> </html>

that code in delphi (xe5):

procedure tform1.button1click(sender: tobject); var doc: ixmldocument; sel: idomnodeselect; list : idomnodelist; query: string; begin content := tfile.readalltext('c:\temp\content.xml'); doc := txmldocument.create(application); doc.loadfromxml(content); doc.active := true; query := '//descendant::html'; sel := doc.domdocument idomnodeselect; list := sel.selectnodes(query); // list.length 0 !!!! end;

the question why list empty, shoud contain 4 elements: html, head, body, h1(that's "html" tag , children. according http://www.w3schools.com/xpath/xpath_syntax.asp xpath syntax i've tried options:

//html/* /html /html/*

none of them works me @ point not know if query ok or code fails in point.

you seem utilize msxml delphi need create sure first call

doc.setproperty('selectionlanguage', 'xpath')

then set

doc.setproperty('selectionnamespaces', 'xmlns:xhtml="http://www.w3.org/1999/xhtml"')

and need utilize prefix xhtml anywhere want qualify elements e.g.

doc.selectnodes('//xhtml:h1')

selects h1 elements.

delphi xpath

No comments:

Post a Comment