如何在元素标记之间创建包含文本的元素

I have made this function:

protected function _addElement($xmlDocument, $elementName, $parentElement){
    $element = $xmlDocument->createElement($elementName);
    return $parentElement->appendChild($element);
}

and I call it, i.e., in this way:

$Street = $this->_addElement($xmlDocument, 'Steet', $xmlDocument);
$House = $this->_addElement($xmlDocument, 'House', $Street);

and in the created XML document I will have it looking like that:

<Street>
   <House //maybe some attributes />
</Street>

So, the createElement($elementName) function is from the DOM API, that I call upon the DOM object $xmlDocument and it will create a closed node. What I need is to use a function that, with which I will get to the following result:

<Street>
   <Yard> the dog pooped all over the backyard </Yard>
</Steet>

I looked in the DOM API for something involving text, etc. I stumbled upon createTextNode($content) but that is something kinda' different, or maybe I just didn't understand correctly, when I read the documentiation.

Since you're using DOMDocument::createElement, you'll notice from the method definition that it has a 2nd non-mandatory argument:

public DOMElement DOMDocument::createElement ( string $name [, string $value ] )

Just update your code to:

protected function _addElement($xmlDocument, $elementName, $elementValue, $parentElement) {
    $element = $xmlDocument->createElement($elementName, $elementValue);
    return $parentElement->appendChild($element);
}

and:

$Street = $this->_addElement($xmlDocument, 'Steet', 'My street', $xmlDocument);
$House  = $this->_addElement($xmlDocument, 'House', 'My house', $Street);

That way you'll be able to add elements with the values you want. Remember that if you want to add attributes to the newly created elements you'll have to use the DOMDocument::createAttribute function on the $element variable before calling appendChild.