php - how to properly adjust XML hierarchy of nodes -


i want create xml file using html form. able create xml file ... while hirarchy come time giving error. please check code or update it. below output want.

output :-<url>todo</url>      <licenses>          <license>              <name>todo</name>              <connection>todo</connection>          </license>      </licenses>

php code:-

$text5 = htmlentities($_post['tb5']);  $text6 = htmlentities($_post['tb6']);  $text7 = htmlentities($_post['tb7']);      $xmlns = 'http://maven.apache.org/pom/4.0';  $document = new domdocument();  $project = $document    ->appendchild($document->createelementns($xmlns, 'project'));  $project->setattributens(        'http://www.w3.org/2001/xmlschema-instance',      'xsi:schemalocation',    'http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd'  );    $project    ->appendchild($document->createelementns($xmlns, 'url'))    ->appendchild($document->createtextnode($text5));      $project    ->appendchild($document->createelementns($xmlns, 'licenses'))     ->appendchild($document->createelementns($xmlns, 'license'))     ->appendchild($document->createelementns($xmlns, 'url'))     ->appendchild($document->createtextnode($text6));     ->appendchild($document->createelementns($xmlns, 'name'))     ->appendchild($document->createtextnode($text7));       $document->save("d.xml");    ?>

you have syntax error in code, after creating text node - needing semantic change dom hierarchy. here's corrected code correcting appendchild $project.

<?php  $text5 = htmlentities($_post['tb5']); $text6 = htmlentities($_post['tb6']); $text7 = htmlentities($_post['tb7']);  $xmlns = 'http://maven.apache.org/pom/4.0'; $document = new domdocument(); $project = $document   ->appendchild($document->createelementns($xmlns, 'project')); $project->setattributens(    'http://www.w3.org/2001/xmlschema-instance',   'xsi:schemalocation',   'http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd' );  $project   ->appendchild($document->createelementns($xmlns, 'url'))   ->appendchild($document->createtextnode($text5));   $license = $project   ->appendchild($document->createelementns($xmlns, 'licenses'))   ->appendchild($document->createelementns($xmlns, 'license')) ;  $license   ->appendchild($document->createelementns($xmlns, 'name'))   ->appendchild($document->createtextnode($text6));  $license   ->appendchild($document->createelementns($xmlns, 'connection'))   ->appendchild($document->createtextnode($text7));  $document->save("d.xml");  ?> 

edit: modified script little match xml output format specified. creating second url node, not proper name/connection node. in place.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -