{"id":2169,"date":"2015-01-03T10:52:38","date_gmt":"2015-01-03T08:52:38","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=2169"},"modified":"2015-01-04T15:21:59","modified_gmt":"2015-01-04T13:21:59","slug":"search-accented-charater-with-the-help-of-xpath","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=2169","title":{"rendered":"Search accented \/ Uppercase charaters with XPath"},"content":{"rendered":"<p>XPath 2.0 is a version of the XPath language defined by the World Wide Web Consortium<br \/>\nXPath is used primarily for selecting parts of an XML document. For this purpose the XML document is modelled as a tree of nodes. XPath allows nodes to be selected by means of a hierarchic navigation path through the document tree.<\/p>\n<p><strong>Function library<\/strong><\/p>\n<p>The function library in XPath 2.0 is greatly extended from the function library in XPath 1.0. (Bold items are available in XPath 1.0)<\/p>\n<p>Some functions available include the following:<br \/>\n<strong>*<span style=\"text-decoration: underline;\">Purpose : Example Functions<\/span><\/strong><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>* General string handling<\/strong><\/span> lower-case, upper-case, substring, substring-before, substring-after, <strong>translate<\/strong>, starts-with, ends-with, contains, string-length, concat, normalize-space, normalize-unicode<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>* Regular expressions<\/strong><\/span> matches, replace, tokenize<\/p>\n<p>However, chances are you&#8217;re stuck with XPath 1.0. In that case, you can abuse the <strong>translate()<\/strong> function:<\/p>\n<p>For my search on unicode file xml under <strong>php library simpleXML<\/strong> I used (Nodes name are case sensitive). A good article about <strong>parsing xml files with simpleXML is <a title=\"Parsing XML With SimpleXML\" href=\"http:\/\/www.sitepoint.com\/parsing-xml-with-simplexml\/\" target=\"_blank\">here<\/a>.<\/strong><\/p>\n<pre>$objXML = simplexml_load_file('includes\/datas\/books.xml');\r\n.....................\r\n\r\n$nm = count($objXML-&gt;xpath(\"\/\/Book[contains(translate(E010\/text(), 'ABCDEFGHJIKLMNOPQRSTUVWXYZ\u00e0\u00e2\u00e8\u00e9\u00ea\u00eb\u00ee\u00ef\u00f4\u00f9\u00fb\u00fc', 'abcdefghjiklmnopqrstuvwxyzaae\u00e9eeiiouuu'), '$search')]\"));\r\n                 $xml = $objXML-&gt;xpath(\"\/\/Eve[contains(translate(E010\/text(), 'ABCDEFGHJIKLMNOPQRSTUVWXYZ\u00e0\u00e2\u00e8\u00e9\u00ea\u00eb\u00ee\u00ef\u00f4\u00f9\u00fb\u00fc', 'abcdefghjiklmnopqrstuvwxyzaae\u00e9eeiiouuu'), '$search')]\");<\/pre>\n<p>For a terms search all uppercase and accents are translated under nodes (for example Alg\u00e9rie to algerie) so we must search in lowercase algerie to find our words &#8230;<\/p>\n<pre> if (isset($_GET['search ']) &amp;&amp; strlen($_GET['search '])&gt;0) {\r\n      $keywords = $_GET['search '];<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>XPath 2.0 is a version of the XPath language defined by the World Wide Web Consortium XPath is used primarily for selecting parts of an XML document. For this purpose the XML document is&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2848,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[32,295,296],"tags":[],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2169"}],"collection":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2169"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2169\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2848"}],"wp:attachment":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}