How do I create a duplicate of an XML element, but change the name of the element and delete the original? [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How do you rename a tag in SimpleXML through a DOM object? If I have an XML document like this: <document> <dogs> <bulldog>Blu</bulldog> <terrier>Benjie</terrier> </dogs> <cats> <tiger>Tiggger</tiger> <lion>Cowardly</lion> </cats> </document> And I want to reprint it, adding some attributes, but not keep the original.... <document> <canine type="fiction"> <bulldog>Blu</bulldog> <terrier>Benjie</terrier> </canine