Jump to content

xPath basic working problems!!!


Guest clesueur
 Share

Recommended Posts

Guest clesueur

Trying to get my head round xml and xpath but ive tried tutorials with no luck so far.. on "http://blog.opject.org/?page_id=4#Conclusion" the tutorial says i just need the code below for the titles to be traced to the output box but ive done this and i get no output at all!Ive updated XFactorstudio’s XPath files but still nothing happens in the output box!Can anyone help?! am i missing something here? im getting totally lost with this now as i cant get things to work. Thank you... (code and xml info below)import mx.xpath.XPathAPI;var books : XML;books = new XML();books.ignoreWhite = true;books.onLoad = function(success : Boolean) : Void{var titles : Array;titles = XPathAPI.selectNodeList(books.firstChild, "/books/*/title/*");trace( titles );};books.load("books.xml");xml file:<?xml version="1.0" encoding="UTF-8" ?><books><book id='0'><author>J.R.R. Tolkien</author><title>The Lord of the Rings</title><isbn>0618346252</isbn><price>34.95</price></book><book id='1'><author>Dan Brown</author><title>The Da Vinci Code<title><isbn>1400079179</isbn><price>17.95</price></book></books>

Link to comment
Share on other sites

"title" doesn't have any child elements. With the part "title/*", you're telling XPath to get the value of the first child element of "title", regardless of its name. But there's no such element, and thus XPath returns nothing.Use the expression:

"/books/*/title"

instead.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...