Permalänk

XML med samma väg

Så jag har en XML fil som jag försöker att hämta information från. Problemet är att vägen är samma på de ställen jag vill ha information från. Jag vill ha information från fcttext

<response> <version>0.1</version> <features> <feature>Day</feature> </features> <information> <txt_day> <date>1:41 PM CEST</date> <days> <day> <period>0</period> <icon>chancerain</icon> <icon_url>chancerain.gif</icon_url> <title>Monday</title> <fcttext><![CDATA[INFORMATION]]></fcttext> </day> <day> <period>1</period> <icon>nt</icon> <icon_url>nt.gif</icon_url> <title>Monday Night</title> <fcttext><![CDATA[INFORMATION]]></fcttext> </day> <day> <period>2</period> ...

Dold text

För att få första raden kör jag,
global_full_day=evaluateXPathAsString(test, "//txt_day/days/day/fcttext");

Fast andra raden är ju samma väg, så att göra detta,
global_full_night=evaluateXPathAsString(test, "//txt_day/days/day/fcttext"); gör ju att jag får första vägen.

Jag läste igenom https://www.w3.org/TR/xpath/#section-Location-Steps men hittade inget som fungera. Troligen så har jag skrivit in det fel med child::para[position()=last()]

Som jag förstår det är att child blir vägen, så det borde bli global_full_night=evaluateXPathAsString(test, "//txt_day/days/day/fcttext"::para[position()=2)]; Men får det inte att fungera.

Någon som vet hur jag kan få den andra delen av informationen?

Permalänk
Medlem

@Frejoh466

/child::doc/child::chapter[position()=5]/child::section[position()=2] Selects the second section of the fifth chapter of the doc document element

Så kanske något i stil med:

//txt_day/days/day[position()=2]/fcttext

Kollat från mobilen, kan vara helt fel

Permalänk

Gick till w3schools och hitta att det skulle vara, global_full_night=evaluateXPathAsString(test, "//txt_day/days/day[2]/fcttext"

Skrivet av hultron:

@Frejoh466

/child::doc/child::chapter[position()=5]/child::section[position()=2] Selects the second section of the fifth chapter of the doc document element

Så kanske något i stil med:

//txt_day/days/day[position()=2]/fcttext

Kollat från mobilen, kan vara helt fel

Detta funkade med. Tackar för hjälpen.