![]() $chapter2 = $xml -> addChild ( "chapter_2" ) $chapter1 -> addAttribute ( "chapter_title", "Introduction to my book" ) $chapter1 = $xml -> addChild ( "chapter_1" ) $xml -> addChild ( "abstract", "My book is about learning to work with SimpleXMLElement" ) $xml -> addChild ( "title", "Title of my book" ) create the SimpleXMLElement object with an empty element just uncoment the following line and change the stylesheet name. optionally you can specify a xml-stylesheet for presenting the results. Here goes my contribution for those whom are struggling to understand how SimpleXMLElement works.Īfter some time trying to figure out how this works, I've came up to this small example: $xml -> addProcessingInstruction ( 'xml-stylesheet', 'type="text/xsl" href="xsl/xsl.xsl"' ) $dom_parent -> insertBefore ( $pi, $first_element ) įor example, if you had a simpleXMLElement_Plus object made out of the xml fragment: $pi = $dom_parent -> createProcessingInstruction ( $name, $value ) Add the processing instruction before the topmost element $first_element = $xpath -> evaluate ( '/*' )-> item ( 0 ) Find the topmost element of the domDocument It's occasionally useful to add an XML processing instruction to a SimpleXMLElement (treating it as if it were a full document). SimpleXMLElement::xpath - Runs XPath query on XML data. ![]() SimpleXMLElement::_toString - Returns the string content.SimpleXMLElement::saveXML - Alias of SimpleXMLElement::asXML.SimpleXMLElement::registerXPathNamespace - Creates a prefix/ns context for the next XPath query.SimpleXMLElement::getNamespaces - Returns namespaces used in document.SimpleXMLElement::getName - Gets the name of the XML element.SimpleXMLElement::getDocNamespaces - Returns namespaces declared in document.SimpleXMLElement::count - Counts the children of an element.SimpleXMLElement::_construct - Creates a new SimpleXMLElement object.SimpleXMLElement::children - Finds children of given node.SimpleXMLElement::attributes - Identifies an element's attributes.SimpleXMLElement::asXML - Return a well-formed XML string based on SimpleXML element. ![]()
0 Comments
Leave a Reply. |