Я пытаюсь добавить узел в XML-файл.
я хочу добавить новый узел после «Я», как это
<NewNode>UN9TD72U</NewNode>
Вот так выглядит мой xml-файл
<?xml version="1.0"?>
<GetProductCategories>
<GetProduct>
<Self>
<ProductCategoryId>1282779353</ProductCategoryId>
<ProductCategoryName>Shirt</ProductCategoryName>
<Parent>
<ProductCategoryId>8363437382</ProductCategoryId>
<ProductCategoryName>Sports tshirt</ProductCategoryName>
</Parent>
</Self>
</GetProduct>
</GetProductCategories>
Мой Код :
$xml = simplexml_load_file("data.xml");
$child = $xml->addChild("NewNode");
$child->addAttribute("text","UN9TD72U");
$xml->asXML("data.xml");
Выход Я получаю
<?xml version="1.0"?>
<GetProductCategories>
<GetProduct>
<Self>
<ProductCategoryId>1282779353</ProductCategoryId>
<ProductCategoryName>Shirt</ProductCategoryName>
<Parent>
<ProductCategoryId>8363437382</ProductCategoryId>
<ProductCategoryName>Sports tshirt</ProductCategoryName>
</Parent>
</Self>
</GetProduct>
<NewNode text="UN9TD72U"/>
</GetProductCategories>