XPath in Coldfusion

TAKEN FROM: http://www.anujgakhar.com/2007/10/31/using-xpath-with-coldfusion/

<cffile action="read" file="#ExpandPath('books.xml')#" variable="myBooks">
<cfset myxml="XmlParse(myBooks)">

<cfscript>
allbooks = XmlSearch(myXml, "catalog/book");  
firstBook = XmlSearch(myXml, "catalog/book[1]");
lastBook = XmlSearch(myXml, "catalog/book[last()]");  
secondLastBook = XmlSearch(myXml, "catalog/book[last()-1]");
countBooks = XmlSearch(myXml, "count(catalog/book)");  
sumPriceAllBooks = XmlSearch(myXml,sum(catalog/book/price)");
bookAuthors = XmlSearch(myXml,"catalog/book/author");  
searchByTitle = XmlSearch(myXml,catalog/book[title='Midnight Rain']/title");
searchByAuthor = XmlSearch(myXml,catalog/book[genre='Fantasy']/title");  
searchById = XmlSearch(myXml,catalog/book[@id='bk109']/title");
</cfscript>

  • 8 أعضاء وجدوا هذه المقالة مفيدة
هل كانت المقالة مفيدة ؟