Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 31

Thread: Read and write XML with PHP

  1. #11
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    Uhhhh.... It looks to me that you are missing the user defined function 'load()'. Now, this brings to mind the need of importing the file (since that is what the load() function is supposed to do). This is only available in PHP5 and is part of the PHP XML DOM built-in processor. See: http://www.w3schools.com/php/php_xml_dom.asp and http://www.topxml.com/php_simplexml/...ction_load.asp

    I've done this before using a php class to parse webpages and extract content, called dynfetcher, see: http://dynfetcher.googlecode.com/svn...cher.class.php

    I think the code listed in the posts above is probably good if you are using PHP5.....
    Last edited by Strangeplant; 11-13-2008 at 02:54 PM. Reason: correct mistakes from memory

  2. #12
    Join Date
    Nov 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hi,

    Please guide me how to modify xml using php.

  3. #13
    Join Date
    Nov 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default modify xml

    hi,

    Please guide me how to modify xml using php.

  4. #14
    Join Date
    Nov 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i don't know what happen ? help me !
    PHP Code:
    <?php
    $xmlDoc 
    = new DOMDocument();
    $xmlDoc->load("test.xml");

    print 
    $xmlDoc->saveXML();


    ?>
    Warning: domdocument::domdocument() expects at least 1 parameter, 0 given in C:\xampp\htdocs\phong_demo\duanmot\index.php on line 2

    Fatal error: Call to undefined method domdocument::load() in C:\xampp\htdocs\phong_demo\duanmot\index.php on line 3

  5. #15
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Very helpful thread and a good help to get some simple rss feeds pulled into other sites!

    However I've a wee question to ask, is there any straight forward way to control how many of the nodes are parsed from the xml file?

    Here's my current php to parse an xml feed;

    PHP Code:
    <?php
    $doc 
    = new DOMDocument();
    $doc->load'xmlFeed.xml' );
      
    $channel $doc->getElementsByTagName"item" );
    foreach( 
    $channel as $item )
    {
      
    $links $item->getElementsByTagName"link" );
      
    $link $links->item(0)->nodeValue;
      
      
    $titles$item->getElementsByTagName"title" );
      
    $title$titles->item(0)->nodeValue;
        
      
    $guids $item->getElementsByTagName"guid" );
      
    $guid $guids->item(0)->nodeValue;
      
      echo 
    "<p><a href=\"$link\"><img src=\"$guid\" alt=\"$title\"></a><br />$title</p>\n\n";
    }

    ?>
    The feed outputs lots of 'item' nodes but i only want the first 2 to parse from the php code.

    Hope I make sense here and thanks again for everybodys input!

  6. #16
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    is it possible to append nodes to an existing xml file instead of creating a new one every time

  7. #17
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey great code CODEEXPLOITER! very useful thank you!!
    1) how can I add the XML encoding line to the php?
    2) I typed the ">" character in the php file but in the XML file shows this instead "&lt;", how can I fix that?
    thanks again

  8. #18
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation try this one...

    i was searching a similar one...found this...

    http://www.ksada.com/knowledge-base/php/read-xml-in-php

  9. #19
    Join Date
    Dec 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I created an account to reply to this response. I really need help making my website work right... I need to allow people to create and modify xml files. It needs to be in some kind of user friendly text editor. I dont want the user to have to enter any code tags or anything like that. Here is an example of my xml file.
    PHP Code:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <content Name="LAWYER">
       <item Border="10" Width="700" Height="500" ><![CDATA[<font color="#ffffff" size="70"><b>Michael T. Gilbert</b></font><br><font color="#ffffff" size="14"><br><br>MICHAEL T. GILBERT, born Manhasset, New York, July 9, 1954;  admitted to bar, 1985, Colorado.<br><br><img src="content/mtg.png"><b>Contact Information:</b><br>Phone:   (970) 325-4570<br>Fax:       (970) 325-4957<br>E-Mail:    <a href=" mgilbert@ouray.net"> mgilbert@ouray.net</a><br>P.O. Box 1359<br>Ouray, Colorado  81427<br><b>Area of Emphasis</b><br>Civil Litigation<br>Municipal Law<br><b>Education:</b><br>University of Colorado (B.A. English, 1977)<br>Cornell University (J.D. , magnum cum laude 1985)<br>Martindale-Hubbell Rating -AV<br><b>Experience:</b><br>2000 to present: Member Reed & Gilbert, Montrose, CO<br>1991 to 1999: Partner Williams, Youle & Koenigs, Denver, CO<br>1990 to 1991: Law Clerk to Judge E.W. Nottingham, US District Court, Denver, CO<br>1985 to 1990: Associate Sherman & Howard, Denver, CO<br><b>Practice Area</b><br>Trials and Appeals in federal and state courts; expertise in complex commercial litigation, such as real estate related matters, construction and contract disputes.<br><b>Community Interests</b><br>Michael enjoys the outdoors, including climbing, hiking, dog sled racing, and fishing.</font><br><br>]]></item>
    </content>
    everything that would need to be edited is within the cdata. I am just looking for ideas if anyone knows anything that could help I would greatly appreciate it!

  10. #20
    Join Date
    Jan 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by vaccuchuoi View Post
    i don't know what happen ? help me !
    PHP Code:
    <?php
    $xmlDoc 
    = new DOMDocument();
    $xmlDoc->load("test.xml");

    print 
    $xmlDoc->saveXML();


    ?>
    Warning: domdocument::domdocument() expects at least 1 parameter, 0 given in C:\xampp\htdocs\phong_demo\duanmot\index.php on line 2

    Fatal error: Call to undefined method domdocument::load() in C:\xampp\htdocs\phong_demo\duanmot\index.php on line 3
    broda put da version of xml in domdocument class like this
    PHP Code:
    <?php
    $xmlDoc 
    = new DOMDocument("1.0");
    $xmlDoc->load("test.xml");

    print 
    $xmlDoc->saveXML();


    ?>
    it ll solve ua problem
    if any1 wana contact me add me on fsd.lions@gmail.com see ya

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
  •