Need urget help (flash+php+xml)

hi guys i need urgent help… i am dead lock… i need to finish this as soon as possible.

my problem is:-
flash > php > xml.
#flash will read data from xml.

  1. flash will send data to php.
  2. php will convert/add data to xml.
  3. than from that xml flash will read data and display.

its comment box, like message posting.

I have succeeded up to making xml data from php. But the problem is each time php is adding data to xml. Its not adding data to next line. it is appending data to xml structure rather than adding data to next line.
here is the php code

 <?php 
// create doctype 
$dom = new DOMDocument("1.0"); 

// create root element 
$root = $dom->createElement("content"); 
$dom->appendChild($root); 
$dom->formatOutput=true; 

//$senderName = $_REQUEST['namE']; 
//$commentAdded .= .$_REQUEST['comments'].; 
// create child element 
$item = $dom->createElement("contents"); 
$root->appendChild($item); 

// create attribute node 
$price = $dom->createAttribute("namE"); 
$item->appendChild($price); 

// create attribute value node 
$priceValue = $dom->createTextNode($_POST['namE']); 
$price->appendChild($priceValue); 

// create attribute node 
$address = $dom->createAttribute("comments"); 
$item->appendChild($address); 

// create attribute value node 
$priceValue = $dom->createTextNode($_POST['comments']); 
$address->appendChild($priceValue); 

// save tree to file 
$dom->save("contacts.xml"); 

//echo $commentAdded; 
// save tree to string 
$order = $dom->save("contacts.xml")."
"; 
?>  

what i need is. It should add data to current xml data structure. to the next line.

realy i need urgent help. Please tell me how to achive this.

i’ll be very thank full to you.
monty

meeh well you have to load it first to be able to append anything to it. It’s 1.36 here and I was just heading to bed, but roughly


$doc = new domDocument;
$doc->load('contacts.xml');
$doc->formatOutput = true;
$sItem = $doc->createElement('contents');
$sItem = $doc->appendChild($sItem);
$sValue = $doc->createTextNode('1010011101');
$sValue = $sItem->appendChild($sValue);
$doc->save("news/newstest.xml"); 

@sekasi: thanks for ur reply but its not working properly.

it is returning me this xml format

<?xml version="1.0"?>
<content>
  <contents name="abe" comments="something"/>
</content>
<content>
  <contents name="xyz" comments="anything"/>
</content>

but i need xml in this format.

<content>
  <contents name="abe" comments="something"/>
  <contents name="xyz" comments="anything"/>
  <contents name="xyz" comments="anything"/>
</content>

And even when its repeting tag its not taking value… on the second line.
thanks for nice reply.

my php code

$dom = new domDocument("1.0");
$dom->load('contacts.xml');

$root = $dom->createElement("content");
$dom->appendChild($root);
$dom->formatOutput=true;
$item = $dom->createElement("contents");
$root->appendChild($item);
$price = $dom->createAttribute("name");
$item->appendChild($price);
$priceValue = $dom->createTextNode($_POST['name']);
$price->appendChild($priceValue);
$address = $dom->createAttribute("comments");
$item->appendChild($address);
$priceValue = $dom->createTextNode($_POST['comments']);
$address->appendChild($priceValue);
$dom->save("contacts.xml");
$order = $dom->save("contacts.xml");

can u plz help me a bit lot… i am noob in php field.

thanks a lot

even when i test this thing from flash it is not adding value to next line…


<?xml version="1.0"?>
<content>
  <contents name="21312334" comments="23423fsafafe"/>
  <!-- it is not adding next line here -->
</content>

it is leading me to frustration.
please help me some one
:frowning:

any one please…
:frowning:
i am looking for solution. i have tried google also, but didn’t found perfect solution.

Please don’t send private messages when google can help you.

Either way.
Try this


<?php
$doc = new DomDocument('1.0');
$root = $doc->createElement('content');
$root = $doc->appendChild($root);
$occ = $doc->createElement('comments');
$occ = $root->appendChild($occ);
$occname = $doc->createAttribute("name");
$occnameval = $doc->createTextNode('mynameisjohn');
$occname->appendChild($occnameval);
$occ->appendChild($occname);
$order = $doc->save("contacts.xml");
echo $order
?>

thanks for your code but its not working. Sorry for private messages… but i am not much familiar with php codes.

thanks a lot for your time.