Search Results

Search found 5 results on 1 pages for 'user560411'.

Page 1/1 | 1 

  • Create attribute in XML

    - by user560411
    Hello. I have the following php code that adds data into XML and works correctly. However, in my second step I will create a form that deletes some of the elements. The problem is that I want to add an ID number and then the PHP file will search for it and delete entire node. My question is how can i add an ID into CD for this to work ? For example ( <cd id="xxxx"> ) Also, any ideas or examples of a code that deletes CD having the ID would be appreciate. insert.php ( my index file with the form ) <h1>Playlist</h1> <form action="insert2.php" method="post"> <fieldset> <label for="TITLE">TITLE:</label><input type="text" id="title" name="title" /><br /> <label for="title">BAND:</label> <input type="text" id="band" name="band"/><br /> <label for="path">YEAR:</label> <input type="text" id="year" name="year" /> <br /> <input type="submit" /> </fieldset> </form> <h2>Current entries:</h2> <p>TITLE - BAND - YEAR</p> <?php $doc = new DOMDocument(); $doc->load( 'insert.xml' ); $CATEGORIES = $doc->getElementsByTagName( "CD" ); foreach( $CATEGORIES as $CD ) { $TITLES = $CD->getElementsByTagName( "TITLE" ); $TITLE = $TITLES->item(0)->nodeValue; $BANDS= $CD->getElementsByTagName( "BAND" ); $BAND= $BANDS->item(0)->nodeValue; $YEARS = $CD->getElementsByTagName( "YEAR" ); $YEAR = $YEARS->item(0)->nodeValue; echo "<b>$TITLE - $BAND - $YEAR\n</b><br>"; } ?> inser2.php ( the main code ) <?php $CD = array( 'TITLE' => $_POST['title'], 'BAND' => $_POST['band'], 'YEAR' => $_POST['year'], ); $doc = new DOMDocument(); $doc->load( 'insert.xml' ); $doc->formatOutput = true; $r = $doc->getElementsByTagName("CATEGORIES")->item(0); $b = $doc->createElement("CD"); $TITLE = $doc->createElement("TITLE"); $TITLE->appendChild( $doc->createTextNode( $CD["TITLE"] ) ); $b->appendChild( $TITLE ); $BAND = $doc->createElement("BAND"); $BAND->appendChild( $doc->createTextNode( $CD["BAND"] ) ); $b->appendChild( $BAND ); $YEAR = $doc->createElement("YEAR"); $YEAR->appendChild( $doc->createTextNode( $CD["YEAR"] ) ); $b->appendChild( $YEAR ); $r->appendChild( $b ); $doc->save("insert.xml"); ?> the XML file <?xml version="1.0" encoding="utf-8"?> <MY_CD> <CATEGORIES> <CD> <TITLE>NEVER MIND THE BOLLOCKS</TITLE> <BAND>SEX PISTOLS</BAND> <YEAR>1977</YEAR> </CD> <CD> <TITLE>NEVERMIND</TITLE> <BAND>NIRVANA</BAND> <YEAR>1991</YEAR> </CD> </CATEGORIES> </MY_CD>

    Read the article

  • Xml add element node using PHP

    - by user560411
    Hello I would like to add an element node in my entire XML file using PHP. I can not get it right and I add it below root. Please share me a clean code so that I understand how it works.. Thank you! My xml is <?xml version="1.0" encoding="utf-8"?> <GameStore> <Game type="adventure"> <TITLE>Assassin's Creed: Brotherhood</TITLE> <PUBLISHER>Ubisoft</PUBLISHER> </Game> <Game type="adventure"> <TITLE>Batman: Arkham Asylum</TITLE> <PUBLISHER>Eidos</PUBLISHER> </Game> </GameStore>

    Read the article

  • PHP Xml add edit delete

    - by user560411
    Hi there. I am kind of new and I have the following XML structure an I would like to have codes that INSERTS DELETES Delete an entire element based on it's TITLE value. EDIT Replace Publisher's value with another value <Game type="XXX"> <TITLE>XXX</TITLE> <PUBLISHER>XXX</PUBLISHER> </Game> This is my XML structure <Game type="adventure"> <TITLE>Assassin's Creed: Brotherhood</TITLE> <PUBLISHER>Ubisoft</PUBLISHER> </Game> <Game type="adventure"> <TITLE>Batman: Arkham Asylum</TITLE> <PUBLISHER>Eidos</PUBLISHER> </Game> </GameStore> Any help would be great and thank you in avdance!

    Read the article

  • Create attribute in existing XML

    - by user560411
    Hello. I have the following php code that inserts data into XML and works correctly. However, I want to add an ID number like below <CD id="xxxx"> My question is how can i add an ID into CD for this to work ? I use form to parse the id. ** the main code ** <?php $CD = array( 'TITLE' => $_POST['title'], 'BAND' => $_POST['band'], 'YEAR' => $_POST['year'], ); $doc = new DOMDocument(); $doc->load( 'insert.xml' ); $doc->formatOutput = true; $r = $doc->getElementsByTagName("CATEGORIES")->item(0); $b = $doc->createElement("CD"); $TITLE = $doc->createElement("TITLE"); $TITLE->appendChild( $doc->createTextNode( $CD["TITLE"] ) ); $b->appendChild( $TITLE ); $BAND = $doc->createElement("BAND"); $BAND->appendChild( $doc->createTextNode( $CD["BAND"] ) ); $b->appendChild( $BAND ); $YEAR = $doc->createElement("YEAR"); $YEAR->appendChild( $doc->createTextNode( $CD["YEAR"] ) ); $b->appendChild( $YEAR ); $r->appendChild( $b ); $doc->save("insert.xml"); ?> the XML file <?xml version="1.0" encoding="utf-8"?> <MY_CD> <CATEGORIES> <CD> <TITLE>NEVER MIND THE BOLLOCKS</TITLE> <BAND>SEX PISTOLS</BAND> <YEAR>1977</YEAR> </CD> <CD> <TITLE>NEVERMIND</TITLE> <BAND>NIRVANA</BAND> <YEAR>1991</YEAR> </CD> </CATEGORIES> </MY_CD>

    Read the article

  • Display attribute from XML using PHP

    - by user560411
    Hello. I need to display the id attribute of CD from the following XML file. I display correctly everything except the id. Any help would be appreciate. display code <?php $doc = new DOMDocument(); $doc->load( 'insert.xml' ); $CATEGORIES = $doc->getElementsByTagName( "CD" ); foreach( $CATEGORIES as $CD ) { $TITLES = $CD->getElementsByTagName( "TITLE" ); $TITLE = $TITLES->item(0)->nodeValue; $BANDS= $CD->getElementsByTagName( "BAND" ); $BAND= $BANDS->item(0)->nodeValue; $YEARS = $CD->getElementsByTagName( "YEAR" ); $YEAR = $YEARS->item(0)->nodeValue; echo "<b>$TITLE - $BAND - $YEAR\n</b><br>"; } ?> XML <?xml version="1.0" encoding="utf-8"?> <MY_CD> <CATEGORIES> <CD id="3231"> <TITLE>NEVER MIND THE BOLLOCKS</TITLE> <BAND>SEX PISTOLS</BAND> <YEAR>1977</YEAR> </CD> <CD id="2453"> <TITLE>NEVERMIND</TITLE> <BAND>NIRVANA</BAND> <YEAR>1991</YEAR> </CD> </CATEGORIES> </MY_CD>

    Read the article

1