xlsx File converter php XML file operation implementation Code (II)

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.