SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: XML and PHP

  1. #1
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML and PHP

    Hello all...

    I have not used XML with PHP still now .But now i have to do so....

    Can any please give me an example that explains how an XML an be created from PHP and how can i parse the XML with php......

    It will really help me a lot.....
    Where there is a will there is a way
    ArunKumar

  2. #2
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something like this?

  3. #3
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ya abviously more usefull...


    Actually here i want to create a XML file from PHP...

    like

    <details>
    <name>blah</name>
    <email> aa@a.com</email>
    </details>

    like this a four details......


    The book is more usefull and a pefect guide for me
    Where there is a will there is a way
    ArunKumar

  4. #4
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Be careful with the encoding you use, when working with XML.

  5. #5
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ..

    As i said i didnt know anything in XML just i know the structure. i am learning fresh..Any idea will help me a lot..

    Also implenetation example will help a lot....
    Where there is a will there is a way
    ArunKumar

  6. #6
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all,..

    Actually I am having a XML file say "aa.xml"

    The record in that file are as

    ************
    <?xml version="1.0" encoding="iso-8859-1"?>
    <gbook>
    <guest>
    <name>arun</name>
    <email>arun@ss.com</email>
    </guest>
    </gbook>
    **********

    when i get a record by POST i have to append a new node at the top.

    how can i ????

    Is there any function ????????????????
    Where there is a will there is a way
    ArunKumar

  7. #7
    SitePoint Enthusiast aLargeTrout's Avatar
    Join Date
    Sep 2005
    Location
    Bucharest, Romania
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take a look at the DOM functions:

    http://ro.php.net/manual/en/ref.domxml.php

    For your particular example, you would need something like this:

    PHP Code:
    $dom domxml_open_file('aa.xml');
    $root $dom->document_element();

    $new $dom->create_element('new_element');
    $root->append_child($new); 
    This just ads an empty element.

  8. #8
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you want to make xml files?
    You can export from mysql as xml.
    Similarly PhpMyAdmin allows you to create a select and export as xml.

    Heres a handy csv to xml converter I use.
    http://www.creativyst.com/Prod/15/

  9. #9
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arunkumar
    ************
    <?xml version="1.0" encoding="iso-8859-1"?>
    <gbook>
    <guest>
    <name>arun</name>
    <email>arun@ss.com</email>
    </guest>
    </gbook>
    **********
    Hi this is a very simple file. So use the functions provided by SimpleXML:
    To open the file as SimpleXM object and process its entries:

    PHP Code:
    if (file_exists('aaa.xml')) { 
    $xml simplexml_load_file('aaa.xml');
    } else {
    exit(
    'Failed to open test.xml.');
    }
    echo 
    $xml->guest[0]->name.' - '.$xml->guest[0]->email
    Will output: arun - arun@ss.com

    And here is a very good introductory article:
    http://www.zend.com/php5/articles/php5-simplexml.php

  10. #10
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you all...

    Here you mentioned about retreiving data from XML..I want to add a date to the XML how can i ??
    Where there is a will there is a way
    ArunKumar

  11. #11
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi all...

    I want to add a data to the XML...say as with the above xml file as

    **************************
    <?xml version="1.0" encoding="iso-8859-1"?>
    <gbook>
    <guest>
    <name>arun</name>
    <email>arun@ss.com</email>
    </guest>
    </gbook>
    *****************

    the file is like this i want to add a data when a user type it from text bos say the data is
    $name = "kumar";
    email = "aw@com";

    i want to add the data such that the xml files look like

    *****************************
    <?xml version="1.0" encoding="iso-8859-1"?>
    <gbook>
    <guest>
    <name>kumar</name>
    <email>aw@com</email>
    </guest>

    <guest>
    <name>arun</name>
    <email>arun@ss.com</email>
    </guest>
    </gbook>
    ************************
    Where there is a will there is a way
    ArunKumar

  12. #12
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the DOM functions, here is a little example:
    PHP Code:
    <?php 
     
    $doc 
    = new DOMDocument();
    $doc->load('aaa.xml');
     
     
    $node $doc->createElement("New node");
    $newnode $doc->appendChild($node);
     
    echo 
    $doc->saveXML();
    ?>


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
  •