Ich habe die folgende XML:XPath enthalten genaue Wort
<book>
<title>Sword of Honour</title>
<category>foo</category>
<author>Evelyn Waugh</author>
</book>
<book>
<title>Moby Dick</title>
<category>foo bar</category>
<author>Herman Melville</author>
</book>
<book>
<title>Sayings of the Century</title>
<category>bar foo</category>
<author>Nigel Rees</author>
</book>
<book>
<title>The Lord of the Rings</title>
<category>bar</category>
<author>J. R. R. Tolkien</author>
</book>
<book>
<title>The Lord</title>
<category>foo,bar</category>
<author>J. Tolkien</author>
</book>
Ich möchte Daten bekommen, wo Kategorie genau "foo" enthält, das wäre:
<book>
<title>The Lord</title>
<category>foo,bar</category>
<author>J. Tolkien</author>
</book>
<book>
<title>Sword of Honour</title>
<category>foo</category>
<author>Evelyn Waugh</author>
</book>
, wenn ich versuche:
//*[contains(category, "foo")]
Es gibt die folgenden Elemente zurück:
<book>
<title>Sword of Honour</title>
<category>foo</category>
<author>Evelyn Waugh</author>
</book>
<book>
<title>Moby Dick</title>
<category>foo bar</category>
<author>Herman Melville</author>
</book>
<book>
<title>Sayings of the Century</title>
<category>bar foo</category>
<author>Nigel Rees</author>
</book>
<book>
<title>The Lord</title>
<category>foo,bar</category>
<author>J. Tolkien</author>
</book>
während, wenn ich versuche:
//*[category="foo"]
es gibt die folgenden Elemente:
<book>
<title>Sword of Honour</title>
<category>foo</category>
<author>Evelyn Waugh</author>
</book>
Gibt es eine Möglichkeit, dass ich meine Daten bekommen konnte. Jede Hilfe wäre willkommen. Dank
'// * [Kategorie =" Foo "]' gibt 2 Bücher für mich – splash58
@ splash58 In Wirklichkeit hatte ich JSON, die mehrere Kategorien mit Kommas getrennt hat. Aber ich konnte keine ähnliche Frage finden. Also habe ich es in XML konvertiert. Würde es funktionieren, wenn ich den zuletzt mit Komma getrennten konvertiere. Bitte sehen Sie sich die aktualisierte Frage an. – hashtagerrors
Ist eine Kategorieliste mit Leerzeichen nach Komma? – splash58