php XPath doc new DOMDocument doc- load electronics xml xpath new DomX

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
//////////// XPath //////////////////////
$doc=new DOMDocument();
$doc->load('electronics.xml');
$xpath = new DomXpath($doc);
$query = $xpath->query('/ICG/Category');
/*debug*/ echo "<hr> /cs_amazon/cs_office-5.11/channels/amazon/tests/test_xml.php <hr><pre>";
/*debug*/ print_r ($query->length); echo "</pre>";
for($i=0; $i < $query->length; $i++) {
$node=$query->item($i);
$doc_save = new DOMDocument();
$node_save=$doc_save->importNode($node, true);
$doc_save->appendChild($node_save);
if (!is_dir($node->getAttribute('name'))) {
if (mkdir($node->getAttribute('name'), 0777)) {
}
else
die('Could not create folder');
}
$folder_name = $node->getAttribute('name');
$file_name = $node->getAttribute('name').'_083.xml';
$cutted_xml = $doc_save->saveXML(); //$folder_name.'/'.$node->getAttribute('name') . '_083.xml'
$doc_save->save($folder_name.'/'.$file_name);
/////////////////////////////////////////////////////////
//////// Types (for exemple <UsedFor>,<ItemType> ////////
/////////////////////////////////////////////////////////
$doc_type=new DOMDocument();
$doc_type->load($folder_name.'/'.$file_name);
$xpath_type = new DomXpath($doc_type);
$query_type = $xpath_type->query('/Category');
echo $doc_type->saveXML();
/*debug*/ echo "<hr> /cs_amazon/cs_office-5.11/channels/amazon/tests/test_xml.php <hr><pre>";
/*debug*/ print_r ($query_type->length); echo "</pre>";
/*
for($k=0; $k < $type_query->length; $k++) {
$node_type = $type_query->item($k);
$doc_save = new DOMDocument();
$node_save=$doc_save->importNode($node_type, true);
$doc_save->appendChild($node_save);
//echo $doc_save->saveXML();
$doc_save->save($folder_name.'/'.$node->nodeName . '.xml');
}
*/
}
?>