Copy CodeThe code is as follows:
To create a new DOM document
$dom = new DomDocument ();
Create a departs label on the root node
$departs = $dom->createelement (' departs ');
$dom->appendchild ($departs);
Create depart sub-labels under the Departs tab
$depart = $dom->createelement (' Depart ');
$departs->appendchild ($depart);
Create employees sub-labels under the Depart tab
$employees = $dom->createelement (' employees ');
$depart->appendchild ($employees);
Create an employee sub-label under the Employees tab
$employee = $dom->createelement (' employee ');
$employees->appendchild ($employee);
Create a Serial_no sub-label under the Employee tab
$serial _no = $dom->createelement (' serial_no ');
$employee->appendchild ($serial _no);
Adding values to the SERIAL_NO tag node 100001
$serial _no_value = $dom->createtextnode (' 100001 ');
$serial _no->appendchild ($serial _no_value);
Output XML data
echo $dom->savexml ();
?>
Copy the Code code as follows:
$dom = new DomDocument (); Creating DOM objects
$dom->load (' example.xml '); Reading an XML file
$root = $dom->documentelement; Gets the root of the XML data
Read_child ($root); Call the Read_child function to read the root object
function Read_child ($node)
{
$children = $node->childnodes; Get all child nodes of $node
foreach ($children as $e)//looping through each child node
{
if ($e->nodetype = = xml_text_node)//output if child nodes are text type
{
echo $e->nodevalue. "
";
}
else if ($e->nodetype = = Xml_element_node)//If the child node is a node object, the calling function handles
{
Read_child ($e);
}
}
}
?>
The above describes the xlsx file converter php XML file operation implementation Code (ii), including the xlsx file converter aspects, I hope to be interested in PHP tutorial friends helpful.