B
B
brokendevice2016-11-11 19:02:23
XPath
brokendevice, 2016-11-11 19:02:23

Is it possible to use Cyrillic in xPath requests?

I parse the XML received from 1C, as you probably guess, all the element headers are written in Russian, Cyrillic.
I'm trying to search for an element using xPath, but it doesn't find anything. I tried to test the simplest queries in order to exclude the possibility of an incorrectly formulated query - the same thing.
In this regard, the question is - is Cyrillic supported in xPath requests?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2016-11-12
@brokendevice

Since it is not known what language we are talking about, the answer will be quite general - yes, Cyrillic can be used in xpath queries.
For example, there is no problem with this in php, provided that the document passed to the DOM is UTF-8 encoded.

$xml = '<СписокВалют>
<результат>
<контент>
<пункт вал1="USD" вал2="RUB">69.966015</пункт>
<пункт вал1="CNY" вал2="KZT">50.799100</пункт>
<пункт вал1="RUB" вал2="KZT">4.859019</пункт>
</контент>
</результат>
</СписокВалют>';

$doc = new DOMDocument('UTF-8');
$doc->loadXML($xml);
$xpath = new DOMXPath($doc);
$res = $xpath->query("//пункт[@вал1='USD']");
echo $res->item(0)->nodeValue;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question