addAttribute() to XML objectWe can add attributes to different elements of XML object by using addAttribute() function. We will try with different examples to add attributes at different level of child node. We used asXML function to display XML string. We have used our sample xml file for this. Here is the code.
Output is here.
Adding attribute to different level of XML node.We will only show the changed line here and the respective output
Now adding to another node
PHP & XML getName(): Name of the XML element or tag children(): Children of a XML node count(): Counting number of Children of an XML element simplexml_load_file(): creating object by reading from XML file simplexml_load_string(): creating object by using XML formatted string asXML: Getting string output or writing to file addAttribute(): Adding attribute to element of XML object addChild(): Adding Child element to element of XML object getNamespaces(): Getting NameSpaces from XML object XML from Database(): Generating XML from table records