<!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="" method="post">
<?php
$file = <<<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>
XML;
/**
* @param SimpleXMLElement $node current node to process
* @param int $level Depth in the XML tree
* @param string $fieldPrefix
*/
function makeNodeField(SimpleXMLElement $node, $level, $fieldPrefix = "")
{
// Indentation with the node level
$indent = str_repeat(" ", $level);
echo $indent, $node->getName(), PHP_EOL;
$fieldName = $fieldPrefix;
// If there's an ID on the node, display it and show a text field
if (isset($node['id'])) {
echo $indent, strval($node['id']), ' ';
if (!empty($fieldPrefix)) {
$fieldName .= '_';
}
$fieldName .= $node->getName() . '_' . strval($node['id']);
printf('<input type="text" name="%s" value="%s" /><br/>', $fieldName, strval($node['value']));
echo PHP_EOL;
}
$count = 0;
foreach ($node as $childNode) {
// put a prefix in the children field name to get a valid field name for POST
$childPrefix = $fieldName;
if (!empty($fieldPrefix)) {
$childPrefix = $fieldName . '_' . $count++;
}
makeNodeField($childNode, $level + 1, $childPrefix);
}
}
$xml = simplexml_load_string($file);
makeNodeField($xml, 0);
?>
</form>
</body>
</html>
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- <!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="" method="post">
catalog
product
123 <input type="text" name="product_123" value="" /><br/>
catalog_item
size
color_swatch
color <input type="text" name="product_123_0_0_color_swatch_color" value="Red" /><br/>
color_swatch
color <input type="text" name="product_123_0_1_color_swatch_color" value="burgundy" /><br/>
size
color_swatch
color <input type="text" name="product_123_1_0_color_swatch_color" value="Red" /><br/>
color_swatch
color <input type="text" name="product_123_1_1_color_swatch_color" value="burgundy" /><br/>
</form>
</body>
</html>
preferences:
113.61 ms | 411 KiB | 5 Q