XML/XPath: Difference between revisions
revert spam |
mNo edit summary |
||
Line 1: | Line 1: | ||
[http://wiellico.125mb.com/html/numeri-cellulari.htm numeri cellulari] [http://nescogin.125mb.com/content/sesso-porne.htm sesso porne] [http://yarobiso.angelfire.com/text/impiegato-post.htm impiegato post vendita (regione trentino alto adige trento provincia)] [http://paryker.125mb.com/styles/aladino/ aladino 2] [http://bedrew.125mb.com/riassunto-libro.htm riassunto libro dieci piccoli indiani] [http://paryker.125mb.com/styles/kit-gps/ kit gps tom] [http://sewehner.125mb.com/articles/lorenzo-il/ lorenzo il magnifico] [http://wiellico.125mb.com/html/cyrus-mono.htm cyrus mono x] [http://dacornel.125mb.com/data/mallawi.htm mallawi] [http://hoadmoni.125mb.com/styles/cara-de/ cara de chango] [http://fikimber.125mb.com/lib/southwest-airlines.htm southwest airlines] [http://tibrown.125mb.com/description/sexy-katia/ sexy katia pedrotti] [http://sewehner.125mb.com/articles/chat-firenze/ chat firenze] [http://degaylor.125mb.com/bigiotteria-etnica/ bigiotteria etnica] [http://sewehner.125mb.com/articles/canon-/ canon 100 macro] [http://ruwier.125mb.com/ilahii/ ilahii] [http://ruwier.125mb.com/buldok/ buldok] [http://morudd.angelfire.com/web/dimmi-dimmi/ dimmi dimmi tatangelo] [http://stjollay.125mb.com/topic/vibrazioni-prodotte/ vibrazioni prodotte da infrastrutture di trasporto in fase di costruzione e di esercizio] [http://wiellico.125mb.com/html/hp.htm hp 4370] [http://yonosoyyo.angelfire.com/directory/autofellatio.htm autofellatio] [http://ruwier.125mb.com/anti-legge/ anti legge no ormoni] [http://ruwier.125mb.com/volo-aereo/ volo aereo bologna palermo] [http://grdugans.angelfire.com/text/i-want.htm i want internet in english] [http://mamans.125mb.com/topic/www-abcarcade.htm www abcarcade com] [http://dacornel.125mb.com/data/www-cronache.htm www cronache rapimenti it] [http://bedrew.125mb.com/km-.htm km 0 fiat panda] [http://elernst.angelfire.com/articles/barash-asher.htm barash asher] [http://tibrown.125mb.com/description/navigatore-gps/ navigatore gps autoradio] [http://kocarawf.125mb.com/blog/tv-dvd.htm tv dvd philips] [http://fikimber.125mb.com/lib/www-dgtv.htm www dgtv it] [http://kocarawf.125mb.com/blog/san-carlos.htm san carlos (uruguay)] [http://sawilson.125mb.com/data/ocean-congelatore.htm ocean congelatore verticale] [http://dleslis.125mb.com/resources/lenau-nikolaus.htm lenau nikolaus] [http://stjollay.125mb.com/topic/anal-toys/ anal toys] [http://nescogin.125mb.com/content/midi-country.htm midi country] [http://ruwier.125mb.com/vacatures/ vacatures] [http://kocarawf.125mb.com/blog/hip-hop.htm hip hop immortals we got your kids] [http://awihimmeru.angelfire.com/pearcing-sexi.htm pearcing sexi] [http://kocarawf.125mb.com/blog/jdo-spa.htm jdo spa] [http://nescogin.125mb.com/content/gottmann-jean.htm gottmann jean] [http://champ-alnite.angelfire.com/splav.htm splav] [http://sawilson.125mb.com/data/e-dimme.htm e dimme che non vuoi morire] [http://paryker.125mb.com/styles/www-unile/ www unile it] [http://sawilson.125mb.com/data/scarica-canzoni.htm scarica canzoni di natale] [http://anethel.angelfire.com/piastra-bistecchiere.htm piastra bistecchiere] [http://sewehner.125mb.com/articles/www-nane/ www nane sexi it] [http://paryker.125mb.com/styles/vacanze-in/ vacanze in liguria surf] [http://stjollay.125mb.com/topic/la-grande/ la grande rinuncia] [http://champ-alnite.angelfire.com/vantec-tornado.htm vantec tornado] [http://hoadmoni.125mb.com/styles/term-rewriting/ term rewriting system] [http://sawilson.125mb.com/data/hd-.htm hd 160 mb] [http://slavfondmeister.angelfire.com/styles/gps-bluetooth.htm gps bluetooth tomtom navigator 3] [http://spdinnie.angelfire.com/html/dlink-wireless/ dlink wireless usb] [http://sawilson.125mb.com/data/viamichelin-com.htm viamichelin com] [http://degaylor.125mb.com/silp-cucina/ silp cucina] [http://bedrew.125mb.com/chamberlin-william.htm chamberlin william henry] [http://sewehner.125mb.com/articles/crrek/ crrek] [http://dacornel.125mb.com/data/ventspils.htm ventspils] [http://ruwier.125mb.com/corsi-d/ corsi d informatica] [http://dleslis.125mb.com/resources/tally.htm tally 9312] [http://bedrew.125mb.com/piegatura-alluminio.htm piegatura alluminio] [http://gitedy.125mb.com/blog/ciao-norma/ ciao norma jean] [http://sawilson.125mb.com/data/tim-mms.htm tim mms] [http://degaylor.125mb.com/foto-dei/ foto dei morti in iraq] [http://hahosmer.angelfire.com/html/fantuzzi-it.htm fantuzzi it] [http://dleslis.125mb.com/resources/opel-vetra.htm opel vetra tuning] [http://yarobiso.angelfire.com/text/saeco-vienna.htm saeco vienna] [http://tibrown.125mb.com/description/toner-xerox/ toner xerox docuprint p8ex] [http://sawilson.125mb.com/data/residence-queen.htm residence queen rimini] [http://dleslis.125mb.com/resources/gente-come.htm gente come noi] [http://anethel.angelfire.com/hbv.htm hbv] [http://grdugans.angelfire.com/text/batteria-amilo.htm batteria amilo d7820] [http://stjollay.125mb.com/topic/volo-aereo/ volo aereo brindisi bologna] [http://blhestrie.125mb.com/web/canon-eos/ canon eos 350d canon] [http://tibrown.125mb.com/description/kataweb-mappe/ kataweb mappe] [http://fikimber.125mb.com/lib/telefono-di.htm telefono di singoli che cercano coppie] [http://blhestrie.125mb.com/web/vestire-i/ vestire i personnaggi] [http://blhestrie.125mb.com/web/akg-k/ akg k141] [http://stjollay.125mb.com/topic/vino/ vino] [http://mamans.125mb.com/topic/tego-caldero.htm tego caldero n] [http://fikimber.125mb.com/lib/saggio-breve.htm saggio breve famiglia italiana] [http://yarobiso.angelfire.com/text/albero-verde.htm albero verde] [http://bedrew.125mb.com/dolgan.htm dolgan] [http://kocarawf.125mb.com/blog/asus-a.htm asus a620 palmari] [http://spdinnie.angelfire.com/html/olimpia-s/ olimpia s] [http://spdinnie.angelfire.com/html/mackay/ mackay] [http://degaylor.125mb.com/hp/ hp 2840] [http://morudd.angelfire.com/web/auto-noleggio/ auto noleggio valencia] [http://gistrate.angelfire.com/html/carla-gantus.htm carla gantus] [http://ruwier.125mb.com/la-canzone/ la canzone dei gabbiani] [http://paryker.125mb.com/styles/houteman/ houteman] [http://awihimmeru.angelfire.com/here-i.htm here i came here i go] [http://dleslis.125mb.com/resources/honda-transalp.htm honda transalp 2000] [http://sawilson.125mb.com/data/frullatore-e.htm frullatore e mixer] [http://requidim.angelfire.com/web/dan-seals.htm dan seals] [http://wiellico.125mb.com/html/brio-telecom.htm brio telecom cordless] [http://sewehner.125mb.com/articles/creativity-spa/ creativity spa] [http://mamans.125mb.com/topic/jhonny-angel.htm jhonny angel testo] [http://gitedy.125mb.com/blog/tchat/ tchat] [http://morudd.angelfire.com/web/profumi-creed/ profumi creed] [http://hoadmoni.125mb.com/styles/testo-hoobastank/ testo hoobastank] [http://ruwier.125mb.com/romagn-mia/ romagn mia] [http://anethel.angelfire.com/carbone-barbecue.htm carbone barbecue] [http://dacornel.125mb.com/data/nokia-.htm nokia 6210 batteria] [http://mamans.125mb.com/topic/rezzori-gregor.htm rezzori gregor von] [http://grdugans.angelfire.com/text/emma-warton.htm emma warton] [http://bedrew.125mb.com/modem-adsl.htm modem adsl dlink] [http://dleslis.125mb.com/resources/banca-popolare.htm banca popolare sondrio] [http://slavfondmeister.angelfire.com/styles/mp-wma.htm mp3 wma hifi] [http://dacornel.125mb.com/data/www-cerchi.htm www cerchi in lega] [http://elernst.angelfire.com/articles/fotocamera-digitale.htm fotocamera digitale nikon 5600] [http://hoadmoni.125mb.com/styles/latin-lover/ latin lover cesare cremonesi] [http://nescogin.125mb.com/content/www-italiasalute.htm www italiasalute it] [http://ruwier.125mb.com/leaving-on/ leaving on a jet plane] [http://nescogin.125mb.com/content/antenna-per.htm antenna per tv auto] [http://mcclaise.angelfire.com/description/scanjet/ scanjet 4600] [http://woharwoo.angelfire.com/data/te-amar/ te amar] [http://elernst.angelfire.com/articles/selznick-david.htm selznick david o] [http://bedrew.125mb.com/www-terigi.htm www terigi it] [http://elernst.angelfire.com/articles/mafia-nocd.htm mafia nocd download] [http://sewehner.125mb.com/articles/pornoshop-lingerie/ pornoshop lingerie] [http://champ-alnite.angelfire.com/kosov.htm kosov] [http://vegrigsb.angelfire.com/resources/distributori-diffusori.htm distributori diffusori b] [http://tibrown.125mb.com/description/ghosthunter/ ghosthunter] [http://stjollay.125mb.com/topic/assicurazione-motorino/ assicurazione motorino] [http://degaylor.125mb.com/egitto-sharm/ egitto sharm el sheikh hilton] [http://bedrew.125mb.com/fatturazione.htm fatturazione] [http://stjollay.125mb.com/topic/gay-che/ gay che si fanno seghe] [http://paryker.125mb.com/styles/jak-zapomniec/ jak zapomniec free mp3] [http://tibrown.125mb.com/description/mpx/ mpx 200] [http://wiellico.125mb.com/html/il-sorriso.htm il sorriso della vita] [http://dleslis.125mb.com/resources/ipaq-compaq.htm ipaq compaq] [http://vegrigsb.angelfire.com/resources/hp-.htm hp plotter 70] [http://yarobiso.angelfire.com/text/hotel-lucoli.htm hotel lucoli aq] [http://tibrown.125mb.com/description/papa-wojtyla/ papa wojtyla francobolli] [http://paryker.125mb.com/styles/mape-concettuali/ mape concettuali] [http://morudd.angelfire.com/web/www-mercedes/ www mercedes lu] [http://bedrew.125mb.com/rover-defender.htm rover defender 90] [http://slavfondmeister.angelfire.com/styles/fotos-proibidas.htm fotos proibidas xxx] [http://blhestrie.125mb.com/web/www-wanadoo/ www wanadoo dk] [http://paryker.125mb.com/styles/fratelli-feltrinelli/ fratelli feltrinelli spa] [http://fikimber.125mb.com/lib/spartiti-zecchino.htm spartiti zecchino d oro] [http://stjollay.125mb.com/topic/oratoria/ oratoria] [http://wiellico.125mb.com/html/casa-mutuo.htm casa mutuo appartamento vendita] [http://sawilson.125mb.com/data/boxster.htm boxster 987] [http://sibeatri.angelfire.com/html/racconti-erotici/ racconti erotici adolescenti] [http://gitedy.125mb.com/blog/ipod-video/ ipod video] [http://mamans.125mb.com/topic/musical-lantern.htm musical lantern] [http://bedrew.125mb.com/forno-a.htm forno a incasso] [http://blhestrie.125mb.com/web/clipart-nozze/ clipart nozze d argento] [http://hoadmoni.125mb.com/styles/monika-brodka/ monika brodka ten] [http://spdinnie.angelfire.com/html/chocolate-choco/ chocolate choco choco] [http://champ-alnite.angelfire.com/aspirapolvere-robot.htm aspirapolvere robot] [http://sewehner.125mb.com/articles/cesare-evora/ cesare evora] [http://bedrew.125mb.com/cordless-desktop.htm cordless desktop mx bluetooth] [http://yarobiso.angelfire.com/text/socialist-hymn.htm socialist hymn] [http://tibrown.125mb.com/description/seggiolino-bicicletta/ seggiolino bicicletta] [http://woharwoo.angelfire.com/data/www-casalinghe/ www casalinghe com] [http://bedrew.125mb.com/polsat-auto.htm polsat auto] [http://fikimber.125mb.com/lib/film-kurt.htm film kurt cobain] [http://tibrown.125mb.com/description/ingrosso-bigiotteria/ ingrosso bigiotteria] [http://requidim.angelfire.com/web/boulling.htm boulling] [http://tibrown.125mb.com/description/la-luce/ la luce dell est lucio battisti] [http://awihimmeru.angelfire.com/annuncio-affitti.htm annuncio affitti reggio calabria] [http://bedrew.125mb.com/jet-stream.htm jet stream] [http://degaylor.125mb.com/culiadas/ culiadas] [http://mcclaise.angelfire.com/description/margarita-astronomia/ margarita (astronomia)] [http://hoadmoni.125mb.com/styles/sopranos/ sopranos] [http://blhestrie.125mb.com/web/info-italy/ info italy klm com] [http://nescogin.125mb.com/content/monitor-sony.htm monitor sony hs75b] [http://hoadmoni.125mb.com/styles/cartelle-termiche/ cartelle termiche] [http://sawilson.125mb.com/data/zoo-berlino.htm zoo berlino] [http://grdugans.angelfire.com/text/viaggio-slovenia.htm viaggio slovenia] [http://stjollay.125mb.com/topic/consiglio-dimagrire/ consiglio dimagrire] [http://stjollay.125mb.com/topic/seleco/ seleco] [http://mamans.125mb.com/topic/venice-amd.htm venice amd 3200] [http://wiellico.125mb.com/html/adriana-volpe.htm adriana volpe 2004] [http://ruwier.125mb.com/bicep-muscle/ bicep muscle teen webcam] [http://morudd.angelfire.com/web/video-porno/ video porno clip] [http://stjollay.125mb.com/topic/o-zone/ o zone dragostea tin dei] [http://mamans.125mb.com/topic/ddr-mhz.htm ddr2 667mhz] [http://wiellico.125mb.com/html/lnb-mti.htm lnb mti] [http://nescogin.125mb.com/content/philips.htm philips 530] [http://gitedy.125mb.com/blog/dizionario-spagnolo/ dizionario spagnolo online] [http://blhestrie.125mb.com/web/ragazza-arles/ ragazza arles] [http://wiellico.125mb.com/html/l-ufologia.htm l ufologia] [http://nescogin.125mb.com/content/decapitazione-di.htm decapitazione di uno statunitense] [http://champ-alnite.angelfire.com/maxtor-sata.htm maxtor sata 80 gb hard disk e floppy] [http://yonosoyyo.angelfire.com/directory/log-e.htm log e attivazioni] [http://sewehner.125mb.com/articles/cavo-usb/ cavo usb tastiera mouse] [http://paryker.125mb.com/styles/orali/ orali] [http://tibrown.125mb.com/description/copia-cd/ copia cd] [http://champ-alnite.angelfire.com/falditas.htm falditas] [http://sewehner.125mb.com/articles/hey-baby/ hey baby bruce channel] [http://vegrigsb.angelfire.com/resources/porno-mum.htm porno mum] [http://blhestrie.125mb.com/web/pinne-da/ pinne da pesca] [http://nescogin.125mb.com/content/bantumi.htm bantumi] [http://mamans.125mb.com/topic/yety-sport.htm yety sport 6] [http://degaylor.125mb.com/elenco-asili/ elenco asili nido privati in ancona] {{task}} |
|||
{{task}} |
|||
Perform the following three XPath queries on the XML Document below: |
Perform the following three XPath queries on the XML Document below: |
||
Line 87: | Line 87: | ||
</cfsavecontent> |
</cfsavecontent> |
||
<cfset xml = xmlParse(xmlString)> |
<cfset xml = xmlParse(xmlString)> |
||
<!--- First Task ---> |
|||
<cfset itemSearch = xmlSearch(xml, "//item")> |
|||
<!--- item = the first Item (xml element object) ---> |
|||
<cfset item = itemSearch[1]> |
|||
<!--- Second Task ---> |
|||
<cfset priceSearch = xmlSearch(xml, "//price")> |
|||
<!--- loop and print each price ---> |
|||
<cfloop from="1" to="#arrayLen(priceSearch)#" index="i"> |
|||
#priceSearch[i].xmlText#<br/> |
|||
</cfloop> |
|||
<!--- Third Task ---> |
|||
<!--- array of all the name elements ---> |
|||
<cfset names = xmlSearch(xml, "//name")> |
|||
<!--- visualize the results ---> |
|||
<cfdump var="#variables#"> |
|||
==[[JavaScript]]== |
|||
[[Category:JavaScript]] |
|||
'''Interpreter:''' Firefox 2.0 |
|||
//create XMLDocument object from file |
|||
var xhr = new XMLHttpRequest(); |
|||
xhr.open('GET', 'file.xml', false); |
|||
xhr.send(null); |
|||
var doc = xhr.responseXML; |
|||
//get first <item> element |
|||
var firstItem = doc.evaluate( '//item[1]', doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; |
|||
alert( firstItem.textContent ); |
|||
//output contents of <price> elements |
|||
var prices = doc.evaluate( '//price', doc, null, XPathResult.ANY_TYPE, null ); |
|||
for( var price = prices.iterateNext(); price != null; price = prices.iterateNext() ) { |
|||
alert( price.textContent ); |
|||
} |
|||
//add <name> elements to array |
|||
var names = doc.evaluate( '//name', doc, null, XPathResult.ANY_TYPE, null); |
|||
var namesArray = []; |
|||
for( var name = names.iterateNext(); name != null; name = names.iterateNext() ) { |
|||
namesArray.push( name ); |
|||
} |
|||
alert( namesArray ); |
|||
Although some browsers support XPath, working with XML is much easier with E4X. |
|||
//create XML object from file |
|||
var xhr = new XMLHttpRequest(); |
|||
xhr.open('GET', 'file.xml', false); |
|||
xhr.send(null); |
|||
var doc = new XML(xhr.responseText); |
|||
//get first <item> element |
|||
var firstItem = doc..item[0]; |
|||
alert( firstItem ); |
|||
//output contents of <price> elements |
|||
for each( var price in doc..price ) { |
|||
alert( price ); |
|||
} |
|||
//add <name> elements to array |
|||
var names = []; |
|||
for each( var name in doc..name ) { |
|||
names.push( name ); |
|||
} |
|||
alert( names ); |
|||
==[[Perl]]== |
|||
[[Category:Perl]] |
|||
use XML::XPath qw(); |
|||
my $x = XML::XPath->new('<inventory ... </inventory>'); |
|||
[$x->findnodes('//item[1]')->get_nodelist]->[0]; |
|||
print $x->findnodes_as_string('//price'); |
|||
$x->findnodes('//name')->get_nodelist; |
|||
==[[PHP]]== |
|||
[[Category:PHP]] |
|||
<?php |
|||
//PHP5 only example due to changes in XML extensions between version 4 and 5 (Tested on PHP5.2.0) |
|||
$doc = DOMDocument::loadXML('<inventory title="OmniCorp Store #45x10^3">...</inventory>'); |
|||
//Load from file instead with $doc = DOMDocument::load('filename'); |
|||
$xpath = new DOMXPath($doc); |
|||
/* |
|||
1st Task: Retrieve the first "item" element |
|||
*/ |
|||
$nodelist = $xpath->query('//item'); |
|||
$result = $nodelist->item(0); |
|||
/* |
|||
2nd task: Perform an action on each "price" element (print it out) |
|||
*/ |
|||
$nodelist = $xpath->query('//price'); |
|||
for($i = 0; $i < $nodelist->length; $i++) |
|||
{ |
|||
//print each price element in the DOMNodeList instance, $nodelist, as text/xml followed by a newline |
|||
print $doc->saveXML($nodelist->item($i))."\n"; |
|||
} |
|||
/* |
|||
3rd Task: Get an array of all the "name" elements |
|||
*/ |
|||
$nodelist = $xpath->query('//name'); |
|||
//our array to hold all the name elements, though in practice you'd probably not need to do this and simply use the DOMNodeList |
|||
$result = array(); |
|||
//a different way of iterating through the DOMNodeList |
|||
foreach($nodelist as $node) |
|||
{ |
|||
$result[] = $node; |
|||
} |
|||
==[[Ruby]]== |
|||
[[Category:Ruby]] |
|||
#Example taken from the REXML tutorial (http://www.germane-software.com/software/rexml/docs/tutorial.html) |
|||
require "rexml/document" |
|||
include REXML |
|||
#create the REXML Document from the string (%q is Ruby's multiline string, everything between the two @-characters is the string) |
|||
doc = Document.new( |
|||
%q@<inventory title="OmniCorp Store #45x10^3"> |
|||
... |
|||
</inventory> |
|||
@ |
|||
) |
|||
# The invisibility cream is the first <item> |
|||
invisibility = XPath.first( doc, "//item" ) |
|||
# Prints out all of the prices |
|||
XPath.each( doc, "//price") { |element| puts element.text } |
|||
# Gets an array of all of the "name" elements in the document. |
|||
names = XPath.match( doc, "//name" ) |
Revision as of 21:58, 29 August 2007
numeri cellulari sesso porne impiegato post vendita (regione trentino alto adige trento provincia) aladino 2 riassunto libro dieci piccoli indiani kit gps tom lorenzo il magnifico cyrus mono x mallawi cara de chango southwest airlines sexy katia pedrotti chat firenze bigiotteria etnica canon 100 macro ilahii buldok dimmi dimmi tatangelo vibrazioni prodotte da infrastrutture di trasporto in fase di costruzione e di esercizio hp 4370 autofellatio anti legge no ormoni volo aereo bologna palermo i want internet in english www abcarcade com www cronache rapimenti it km 0 fiat panda barash asher navigatore gps autoradio tv dvd philips www dgtv it san carlos (uruguay) ocean congelatore verticale lenau nikolaus anal toys midi country vacatures hip hop immortals we got your kids pearcing sexi jdo spa gottmann jean splav e dimme che non vuoi morire www unile it scarica canzoni di natale piastra bistecchiere www nane sexi it vacanze in liguria surf la grande rinuncia vantec tornado term rewriting system hd 160 mb gps bluetooth tomtom navigator 3 dlink wireless usb viamichelin com silp cucina chamberlin william henry crrek ventspils corsi d informatica tally 9312 piegatura alluminio ciao norma jean tim mms foto dei morti in iraq fantuzzi it opel vetra tuning saeco vienna toner xerox docuprint p8ex residence queen rimini gente come noi hbv batteria amilo d7820 volo aereo brindisi bologna canon eos 350d canon kataweb mappe telefono di singoli che cercano coppie vestire i personnaggi akg k141 vino tego caldero n saggio breve famiglia italiana albero verde dolgan asus a620 palmari olimpia s mackay hp 2840 auto noleggio valencia carla gantus la canzone dei gabbiani houteman here i came here i go honda transalp 2000 frullatore e mixer dan seals brio telecom cordless creativity spa jhonny angel testo tchat profumi creed testo hoobastank romagn mia carbone barbecue nokia 6210 batteria rezzori gregor von emma warton modem adsl dlink banca popolare sondrio mp3 wma hifi www cerchi in lega fotocamera digitale nikon 5600 latin lover cesare cremonesi www italiasalute it leaving on a jet plane antenna per tv auto scanjet 4600 te amar selznick david o www terigi it mafia nocd download pornoshop lingerie kosov distributori diffusori b ghosthunter assicurazione motorino egitto sharm el sheikh hilton fatturazione gay che si fanno seghe jak zapomniec free mp3 mpx 200 il sorriso della vita ipaq compaq hp plotter 70 hotel lucoli aq papa wojtyla francobolli mape concettuali www mercedes lu rover defender 90 fotos proibidas xxx www wanadoo dk fratelli feltrinelli spa spartiti zecchino d oro oratoria casa mutuo appartamento vendita boxster 987 racconti erotici adolescenti ipod video musical lantern forno a incasso clipart nozze d argento monika brodka ten chocolate choco choco aspirapolvere robot cesare evora cordless desktop mx bluetooth socialist hymn seggiolino bicicletta www casalinghe com polsat auto film kurt cobain ingrosso bigiotteria boulling la luce dell est lucio battisti annuncio affitti reggio calabria jet stream culiadas margarita (astronomia) sopranos info italy klm com monitor sony hs75b cartelle termiche zoo berlino viaggio slovenia consiglio dimagrire seleco venice amd 3200 adriana volpe 2004 bicep muscle teen webcam video porno clip o zone dragostea tin dei ddr2 667mhz lnb mti philips 530 dizionario spagnolo online ragazza arles l ufologia decapitazione di uno statunitense maxtor sata 80 gb hard disk e floppy log e attivazioni cavo usb tastiera mouse orali copia cd falditas hey baby bruce channel porno mum pinne da pesca bantumi yety sport 6 elenco asili nido privati in ancona
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Perform the following three XPath queries on the XML Document below:
- Retrieve the first "item" element
- Perform an action on each "price" element (print it out)
- Get an array of all the "name" elements
XML Document:
<inventory title="OmniCorp Store #45x10^3"><item upc="123456789" stock="12"> <name>Invisibility Cream</name> <price>14.50</price> <description>Makes you invisible</description> </item> <item upc="445322344" stock="18"> <name>Levitation Salve</name> <price>23.99</price> <description>Levitate yourself for up to 3 hours per application</description> </item> <item upc="485672034" stock="653"> <name>Blork and Freen Instameal</name> <price>4.95</price> <description>A tasty meal in a tablet; just add water</description> </item> <item upc="132957764" stock="44"> <name>Grob winglets</name> <price>3.56</price> <description>Tender winglets of Grob. Just add water</description> </item> </inventory>
C#
XmlReader XReader; // Either read the xml from a string ... XReader = XmlReader.Create(new StringReader("<inventory title=... </inventory>")); // ... or read it from the file system. XReader = XmlReader.Create("xmlfile.xml"); // Create a XPathDocument object (which implements the IXPathNavigable interface) // which is optimized for XPath operation. (very fast). IXPathNavigable XDocument = new XPathDocument(XReader); // Create a Navigator to navigate through the document. XPathNavigator Nav = XDocument.CreateNavigator(); Nav = Nav.SelectSingleNode("//item"); // Move to the first element of the selection. (if available). if(Nav.MoveToFirst()) { Console.WriteLine(Nav.OuterXml); // The outer xml of the first item element. } // Get an iterator to loop over multiple selected nodes. XPathNodeIterator Iterator = XDocument.CreateNavigator().Select("//price"); while (Iterator.MoveNext()) { Console.WriteLine(Iterator.Current.Value); } Iterator = XDocument.CreateNavigator().Select("//name"); // Use a generic list. List<string> NodesValues = new List<string>(); while (Iterator.MoveNext()) { NodesValues.Add(Iterator.Current.Value); } // Convert the generic list to an array and output the count of items. Console.WriteLine(NodesValues.ToArray().Length);
ColdFusion
<cfsavecontent variable="xmlString"> <inventory ... </inventory> </cfsavecontent> <cfset xml = xmlParse(xmlString)>