The previous article documented the PHP process of creating an XML document, which records how data and attribute values in the received XML string are parsed for further processing of the data.
XML file
1.
2.
3.
4.
5.
6.
7. spot411
8. spot411
9.
10.
11.
12.
13. Pmlal
14. Pmlal
15. Pmlal
16. Pmlal
17. Pmlal
18. Pmlal
19.
20.
21st.
22.
23. Teasavant
24. Teasavant
25. Teasavant
26.
27.
28. Teasavant
29. Teasavant
30. Teasavant
31. Teasavant
32. Teasavant
33.
34.
35. Red8interactive
36. Red8interactive
37. Red8interactive
38. Red8interactive
39. Red8interactive
40. Red8interactive
41. Red8interactive
42. Red8interactive
43.
44.
45.
46.
47.
1. $xml = new DOMDocument ();
2.
3.//$xml->load ("Timeline.xml");
4. $xmlstring = ' spot411 spot411 Pmlal Pmlal Pmlal Pmlal Pmlal Pmlal Teasavant Teasavant Teasavant Teasavant Teasavant Teasavant Teasavant Teasavant red8interactive Red8inter Active red8interactive red8interactive red8interactive red8interactive red8interactive red8interactive ';
5. $xml->loadxml ($xmlstring);
6.
7. $timedom = $xml->getelementsbytagname ("Time");
8. $d _array = Array ();
9. foreach ($timedom as $times) {
$time _att_value = $times->getattribute ("value");
echo $time _att_value. "
";
$d _worker = $times->getelementsbytagname ("worker");
. foreach ($d _worker as $d _work) {
$worker _att_id = $d _work->getattribute ("id");
$worker _att_name = $d _work->getattribute ("name");
echo $worker _att_name. "
";
//echo $worker _att_id. "
";
$d _hours = $d _work->getelementsbytagname ("hour");
. foreach ($d _hours as $d _hour) {
$hour _att_pid = $d _hour->getattribute ("pid");
$hour _att_pmid = $d _hour->getattribute ("PMID");
22.
. Echo Count ($d _hour);
echo $d _hour->nodevalue. "
";
25.}
26.}
27.}
If it is an XML file, use the
$xml->load ("Timeline.xml");
If parsing an XML string, use the
$xml->loadxml ($xmlstring);
------------------------------------------------------
Get Node Properties: getattribute (' id ');
Get node value: nodevalue;
This article is from "Bob" blog
http://www.bkjia.com/PHPjc/478703.html www.bkjia.com true http://www.bkjia.com/PHPjc/478703.html techarticle The previous article documented the PHP process of creating an XML document, which records how data and attribute values in the received XML string are parsed for further processing of the data. XML file ...