SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML element update

    I have an XML file :

    <?xml version="1.0" encoding="utf-8"?>
    <about>
    <name>clients</name>
    <labdat>24.3.2006, 12:36</labdat>
    <showit>1</showit>
    <text>dfgsdfg s sdfgsdf sf gsfg sf</text>
    </about>


    The values from <about> element need to be updated no appended a new one.

    This is a prety code to append to that file, but don't know how to just update


    Code:
    $doc = domxml_open_file($filename);
    $root = $doc->document_element();
    
    $aboutElement = $doc->create_element("about"); 
    
    $nm = $doc->create_element("name");
    $nm = $root->append_child($nm);
    $nmtext = $doc->create_text_node($_POST['name']);
    $nmtext = $nm->append_child($nmtext); 
    
    $ld = $doc->create_element("labdat");
    $ld = $root->append_child($ld);
    $ldtext = $doc->create_text_node($dtearr);
    $ldtext = $ld->append_child($ldtext); 
    
    $sw = $doc->create_element("showit");
    $sw = $root->append_child($sw);
    $swtext = $doc->create_text_node($_POST['vis']);
    $swtext = $sw->append_child($swtext); 
    
    $tx = $doc->create_element("teksts");
    $tx = $root->append_child($tx);
    $txtext = $doc->create_text_node($_POST['text']);
    $txtext = $tx->append_child($txtext); 
    
    $root->append_child($aboutElement); 
    
    $doc->dump_file($filename);

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The values from <about> element need to be updated no appended a new one.
    Post an example of how the xml file should look after the changes.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?xml version="1.0" encoding="utf-8"?>
    <about>
    <name>NEW posted value</name>
    <labdat>24.3.2006, 12:36</labdat>
    <showit>1</showit>
    <text>NEW posted value</text>
    </about>

  4. #4
    SitePoint Evangelist anjanesh's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice example tipone - can you post the same code using DOM instead of DOM XML ?
    Anjanesh

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which version of php are you using and what xml extension are you using?

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud
    Which version of php are you using and what xml extension are you using?

    PHP4

    good question about extension
    on my dev server is php_xmlrpc
    on client server ...... also

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is XML-RPC?

    It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet.
    I'm asking what software you have installed for parsing xml files?

    The DOM XML extension has been overhauled in PHP 4.3.0 to better comply with the DOM standard. The extension still contains many old functions, but they should no longer be used.
    Apparently the "DOM XML" extension is error prone and therefore:
    Note: This extension has been moved to the PECL repository and is no longer bundled with PHP as of PHP 5.0.0.

    Note: This extension is no longer marked experimental. It will, however, never be released with PHP 5, and will only be distributed with PHP 4.
    I've seen people on this forum recommend the simpleXML extension, so maybe you should install that extension. Otherwise, see the user notes here for how to change text nodes with the DOM XML extension:

    http://us3.php.net/manual/en/functio...et-content.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •