How would I go about adding text into an XML element? For example:
<videoTitle>I want to add text here</videoTitle>
I have created the DOMDocument, and begun adding the elements. Here is the element that I need to add the text to.
$title = $vitals->appendChild($X->createElement("title"));
You need to use DOMDocument::createTextNode
$text = $X->createTextNode('Some text here');
$title->appendChild($text);
Alternatively, you can use the shortcut syntax of DOMNode::$nodeValue
:
$title->nodeValue = 'Some text here';
You have to remember with this technique that nodeValue
sets the text content, not the XML content. Tags are escaped, not parsed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With