Jump to content

Collin

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Everything posted by Collin

  1. I don't have access to the server, so compiling PHP in not really an option... And I have made all the stuff to be able to edit this xml file (which holds the tree for navigation on my site), so I don't want to use this xml file as an array. I just want to be able to save these special characters in my xml file without triggering an error. I've tried some stuff with htmlentities() and utf8_decode(), but I have no idea what i'm doing, and why... I just use the DomDocument->load() and DomDocument->save() methods, so I guess I just need to encode/decode the xml file before/after loading/saving... But I don't understand why I get an "not proper utf-8" error when I'm using an ISO character set... I've also tried setting it as an utf-8 xml file, but to no avail... edit: I forgot to mention that I get the input for changing anything in my xml file through a form (a textbox).
  2. I have an xml file and all goes well when loading it, until I use "special characters" as é, è, à,... There I get the error: [b]Input is not proper UTF-8, indicate encoding.[/b] And in the xml file I find a "?" where there should be an é, è or à. In the xml file I have the declaration: [b]<?xml version="1.0" encoding="ISO-8859-1"?>[/b] so what do I need to do to get these "special characters" in my xml file, if his declaration doesn't say to php "use this character set"? I have searched for an answer, but I just don't understand what they're saying about encoding and stuff... Help please! :-(
  3. As far as I know you cannot use variables in Xpath expressions (or at least I have never gotten it to work). A nice tutorial on expath expressions: [a href=\"http://www.zvon.org/xxl/XPathTutorial/General/examples.html\" target=\"_blank\"]http://www.zvon.org/xxl/XPathTutorial/General/examples.html[/a] What you can do is look for all elements with the "type" tag, and go through them all and only show those that have the value of "$myVar". I don't have any experience with simpleXml stuff, but I hope you get the idea if the syntax is not really correct... Hope it helps.... [code]<?php   $s = simplexml_load_file('19space.xml');   $myVar="19W4";      $products = $s->xpath('//product'); //search for all "product" elements       foreach($products as $product) //go through list of all products   {            //if the type of $product matches user input (ie $myVar)        if ($product->type == $myVar)        {            echo "Found {$product->type} <br />";     }    } ?>[/code]
  4. Hello all! :) I've run in a bit of trouble and can't figure out what's wrong... I'm using PHP5 I have an xml document and I want to edit it. It's used for making a navigation tree, so it's full of "url" tags... I can read it (the navigation tree shows up you as I want it), I can change values and attributes of tags in the xml document, but I cannot add new nodes to the document... :( It's quite straight forward: create an element, and add it to the end of the children of a node. The problem is that the "create_element()" method doesn't return an object. In fact it doesn't return anything I can detect... :( the error is: [b]domnode::append_child() expects parameter 1 to be object[/b] I've read up on this, and most problems arise from not enabling the XMLDOC extension in the PHP.ini, but since I can do all things "dom", I don't think the extension is the problem... Other than that I haven't found any real solutions... :( Maybe there is something... Can you only add new nodes to a [b]new[/b] document, and not an existing one? Or can't I add anything using xpath? This is the code: [code]        global $xPath,$xmlDoc,$root;                  $xPathResult = xpath_eval($xPath, "//@id");                  foreach ($xPathResult->nodeset as $currentNode)         {             if ($currentNode->value == $_GET['lte'])             {                 $currentNode = $currentNode->parent_node();                 $newNode = $xmlDoc->create_element("url");                 $currentNode->append_child($newNode);             }         } [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.