Grima  2018-08
Whispering into Alma's ear
Classes | Functions
grima-xmlbag.php File Reference

Go to the source code of this file.

Classes

class  XMLAsArrayOfWhateversSpecifiedByXPath
 
class  XMLAsArrayOfDOMNodesSpecifiedByXPath
 
class  XMLAsArrayOfDOMNodeListsSpecifiedByXPath
 
class  XMLAsArrayOfStringsSpecifiedByXPath
 

Functions

 xml_debug ( $obj)
 
 test ()
 

Function Documentation

◆ test()

test ( )

Definition at line 192 of file grima-xmlbag.php.

192  {
193  $xml = file_get_contents("item-sample.xml");
194  $item_item_data = new XMLAsArrayOfStringsSpecifiedByXPath( $xml, "/item/item_data" );
195  print "EnumerationA: " . $item_item_data['enumeration_a'] . "\n\n";
196  $item_item_data['enumeration_a'] = "NOOOOOOOOO";
197  print $item_item_data->xml->saveXML();
198 }

◆ xml_debug()

xml_debug (   $obj)

Definition at line 19 of file grima-xmlbag.php.

19  {
20  $retval = get_class($obj)."\n";
21  switch(true) {
22  case ($obj instanceof DOMDocument):
23  $retval .= "XPath: {$obj->getNodePath()}\n".$obj->saveXML($obj);
24  break;
25  case ($obj instanceof DOMElement):
26  $retval .= "XPath: {$obj->getNodePath()}\n".$obj->ownerDocument->saveXML($obj);
27  break;
28  case ($obj instanceof DOMAttr):
29  $retval .= "XPath: {$obj->getNodePath()}\n".$obj->ownerDocument->saveXML($obj);
30  break;
31  case ($obj instanceof DOMNodeList):
32  $retval .= "NodeList of length {$obj->length}\n";
33  print $retval;
34  for ($i = 0; $i < $obj->length; $i++) {
35  $retval .= "Item #$i, " . xml_debug($obj->item($i));
36  }
37  break;
38  default:
39  return "Instance of unknown class";
40  }
41  return $retval;
42 }
xml_debug( $obj)