Browse Source

Properly create DOMNodes with a text content (beware of XML entities inside the text)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3829 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 9 years ago
parent
commit
7cf95392a0
1 changed files with 17 additions and 0 deletions
  1. 17 0
      setup/modelfactory.class.inc.php

+ 17 - 0
setup/modelfactory.class.inc.php

@@ -429,6 +429,7 @@ class ModelFactory
 			$oModuleNode->setAttribute('id', $oModule->GetId());
 			$oModuleNode->AppendChild($this->oDOMDocument->CreateElement('root_dir', $oModule->GetRootDir()));
 			$oModuleNode->AppendChild($this->oDOMDocument->CreateElement('label', $oModule->GetLabel()));
+			
 			$this->oModules->AppendChild($oModuleNode);
 			
 			foreach($aDataModels as $sXmlFile)
@@ -1995,6 +1996,22 @@ class MFDocument extends DOMDocument
 		}
 		return parent::saveXML();
 	}
+	
+	/**
+	 * Overload createElement to make sure (via new DOMText) that the XML entities are
+	 * always properly escaped
+	 * (non-PHPdoc)
+	 * @see DOMDocument::createElement()
+	 */
+	function createElement($sName, $value = null, $namespaceURI = null)
+	{
+		$oElement = $this->importNode(new MFElement($sName, null, $namespaceURI));
+		if (!empty($value))
+		{
+			$oElement->appendChild(new DOMText($value));
+		}
+		return $oElement;
+	}
 	/**
 	 * For debugging purposes
 	 */