I want a code to read xml file and get all its node values recursively and check the level of nodes too.print every node and if level of node is 2 or more than 2 print a text field in front of node name. but i am not getting any node value.thank you in advance
my code:
<!DOCTYPE html>
<html>
<head> INSERT VALUES OF THE GIVEN PHRASE IDS : </head>
<!-- <head> <link rel="stylesheet" type="text/css" href="style.css" /></head> -->
<body>
<form name="form" action="xmlform.php" method="post">
<?php
echo ("<pre>");
$file="english.xml";
if(file_exists($file))
{
$xml=simplexml_load_file("$file") or die("Error: Cannot create object");
foreach ($xml as $xmlRoot => $value) {
$lvl=0;
$xmlNode=$value->children();
//if(is_null($value->children())) {echo "true";}exit();
echo '<input type="text" name="xmlNode" value="'.$xmlNode.'" > <br>';
function makeAFieldForNode($xmlNode, $lvl) {
if ($lvl >= 2) {
echo '<input type="text" value="" name="value"> <br>';
}
$newLvl = $lvl++;
foreach ( $xmlNode->children() as $xn) {
makeAFieldForNode($xN, $newLvl);
}
}
makeAFieldForNode();
}
}
echo ("</pre>");
?>
</form>
</body>
</html>
english.xml
<?xml version="1.0"?>
<?xml-stylesheet href="catalog.xsl" type="text/xsl"?>
<!DOCTYPE catalog SYSTEM "catalog.dtd">
<catalog>
<product description="Cardigan Sweater" id="123" value="" product_image="cardigan.jpg">
<catalog_item gender="Men's">
<size description="Medium">
<color_swatch image="red_cardigan.jpg" id="color" value="Red"/>
<color_swatch image="burgundy_cardigan.jpg" id="color" value="burgundy"/>
</size>
<size description="Large">
<color_swatch image="red_cardigan.jpg" id="color" value="Red"/>
<color_swatch image="burgundy_cardigan.jpg" id="color" value="burgundy"/>
</size>
</catalog_item>
</product>
</catalog>
i want a form in output if u see above xml file i want some thing like this
catalog
product
123 (123 is id and text field for value infront of it )
catalog-item
size
color_swatch
color (color id id of color_swatch and text field for value)
so if i add some value on submission button i can generate a new xml file like the one which already exist but with new values of ids of respective elements. For right now i am trying to generate that form with all elements of xml file. I want a dynamic code so whatever xml file it is . my code should read every element and read it and give id and text field for value.I hope you are getting my point.