tags:

views:

507

answers:

3

I don't want a search for the string value to be case insensitive. I want to do a search for the node without regard for case sensitivity. If the XML looks like this:

<items>
   <ITEM>My text!</ITEM>
</items>

I need something like this to work:

$someXmlDoc->xpath("/items/item/text()");

Currently, only this works:

$someXmlDoc->xpath("/items/ITEM/text()");
+1  A: 

There is no case conversion in xpath 1.0 as supported by php (see http://jp.php.net/manual/en/class.domxpath.php)

you could use the translate function, shown below in a very limited sense. note: not recommended as it won't work for non-english characters

/items/*[translate(node(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'item']/text()

you could also do a union as below

/items/ITEM/text() | /items/item/text()
Jonathan Fingland
The union works, but the translate does not. I am accepting for that answer. Thanks :)
hal10001
A: 

This is weird. XML tags are case-sensitive (http://www.w3schools.com/xml/xml_syntax.asp), so <item> and <ITEM> are two different tags. Thus. "/items/item/text()" and /items/ITEM/text() are two different paths.

<items>
   <ITEM>My text!</ITEM>
   <item>Your text!</item>
</items>

"My text" and "Your text" have different xpaths

Max Kosyakov
A: 
VolkerK