![]() $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). With this script you can just copy-paste and try to understand how it works. print the SimpleXMLElement as a XML well-formed string insert the header to tell the browser how to read the document $conclusion = $xml -> addChild ( "conclusion", "The ending of my book" ) $chapter3 -> addAttribute ( "chapter_title", "Another chapter of my book" ) $chapter3 = $xml -> addChild ( "chapter_3" ) $chapter2 -> addAttribute ( "chapter_title", "Development of my book" ) $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: SimpleXMLElement::xpath - Runs XPath query on XML data.SimpleXMLElement::valid - Check whether the current element is valid.SimpleXMLElement::_toString - Returns the string content.SimpleXMLElement::saveXML - Alias of SimpleXMLElement::asXML. ![]() SimpleXMLElement::rewind - Rewind to the first element.SimpleXMLElement::registerXPathNamespace - Creates a prefix/ns context for the next XPath query.SimpleXMLElement::next - Move to next element.SimpleXMLElement::key - Return current key.SimpleXMLElement::hasChildren - Checks whether the current element has sub elements.SimpleXMLElement::getChildren - Returns the sub-elements of the current element.SimpleXMLElement::getNamespaces - Returns namespaces used in document.SimpleXMLElement::getName - Gets the name of the XML element.SimpleXMLElement::getDocNamespaces - Returns namespaces declared in document.SimpleXMLElement::current - Returns the current element.SimpleXMLElement::count - Counts the children of an element.SimpleXMLElement::_construct - Creates a new SimpleXMLElement object. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |