Podczas pracy z xpath (która nie była zbyt długa), natknąłem się na coś dziwnego.Dlaczego wyrażenie wyboru pozycji xpath zwraca wiele węzłów?
skróconego XML (pełna XML jest here i migawki są dostępne na pastebin)
<?xml version="1.0" encoding="utf-8" ?>
<body copyright="All data copyright San Francisco Muni 2013.">
<route tag="all">
<message id="10268" creator="jflynn" startBoundary="1378121400000" startBoundaryStr="Mon, Sep 02 04:30:00 PDT 2013" endBoundary="1378191540000" endBoundaryStr="Mon, Sep 02 23:59:00 PDT 2013" sendToBuses="false">
<text>Sunday schedules today.</text>
</message>
</route>
<route tag="44">
<message id="10221" creator="mlee" startBoundary="1377525600000" startBoundaryStr="Mon, Aug 26 07:00:00 PDT 2013" endBoundary="1382857140000" endBoundaryStr="Sat, Oct 26 23:59:00 PDT 2013" sendToBuses="false">
<routeConfiguredForMessage tag="44"> <stop tag="6420" title="Silver Ave & Revere Ave" />
</routeConfiguredForMessage>
<text>Stop moved across Revere During Construction</text>
</message>
<message id="10222" creator="mlee" startBoundary="1377525600000" startBoundaryStr="Mon, Aug 26 07:00:00 PDT 2013" endBoundary="1382857140000" endBoundaryStr="Sat, Oct 26 23:59:00 PDT 2013" sendToBuses="false">
<routeConfiguredForMessage tag="44"> <stop tag="6420" title="Silver Ave & Revere Ave" />
</routeConfiguredForMessage>
<text>Stop moved across Revere During Construction</text>
</message>
</route>
</body>
Wyrażenie
//route[1]
zwrócone pierwsze route
węzeł się jak oczekiwano. Jednak gdy próbuje wybrać pierwszą message
węzeł, z
//message[1]
stwardnienie message
węzłów zostały zwrócone, a nie tylko jeden.
Początkowo założyłem, że był to problem z platformą, ale testy na systemie Android, Java na komputer i kilku testerów online xpath przyniosły takie same wyniki.
Co może być problemem?
Bardzo dobre i fundamentalne pytanie .. * + 1 * za to samo .. –
możliwy duplikat [otrzymanie pierwszego węzła w zestawie wyników xpath] (http://stackoverflow.com/questions/9199415/getting-first- node-in-xpath-result-set) –