Class Cdata

Cdata

A representation of an XML CDATASection node.

 // 
  
 Create 
  
 and 
  
 log 
  
 an 
  
 XML 
  
 document 
  
 that 
  
 shows 
  
 how 
  
 special 
  
 characters 
  
 like 
  
 '<' 
 , 
  
 '>' 
 , 
  
 and 
  
 '&' 
  
 are 
 // 
  
 stored 
  
 in 
  
 a 
  
 CDATASection 
  
 node 
  
 as 
  
 compared 
  
 to 
  
 in 
  
 a 
  
 Text 
  
 node 
 . 
 var 
  
 illegalCharacters 
  
 = 
  
 '<em>The Amazing Adventures of Kavalier & Clay</em>' 
 ; 
 var 
  
 cdata 
  
 = 
  
 XmlService 
 . 
 createCdata 
 ( 
 illegalCharacters 
 ); 
 var 
  
 text 
  
 = 
  
 XmlService 
 . 
 createText 
 ( 
 illegalCharacters 
 ); 
 var 
  
 root 
  
 = 
  
 XmlService 
 . 
 createElement 
 ( 
 'root' 
 ) 
 . 
 addContent 
 ( 
 cdata 
 ) 
 . 
 addContent 
 ( 
 text 
 ); 
 var 
  
 document 
  
 = 
  
 XmlService 
 . 
 createDocument 
 ( 
 root 
 ); 
 var 
  
 xml 
  
 = 
  
 XmlService 
 . 
 getPrettyFormat 
 () 
 . 
 format 
 ( 
 document 
 ); 
 Logger 
 . 
 log 
 ( 
 xml 
 ); 

Methods

Method Return type Brief description
Text Appends the given text to any content that already exists in the node.
Content Detaches the node from its parent Element node.
Element Gets the node's parent Element node.
String Gets the text value of the Text node.
String Gets the text value of all nodes that are direct or indirect children of the node, in the order they appear in the document.
Text Sets the text value of the Text node.

Detailed documentation

append(text)

Appends the given text to any content that already exists in the node.

Parameters

Name Type Description
text
String the text to append to the node

Return

Text — the Text node, for chaining


detach()

Detaches the node from its parent Element node. If the node does not have a parent, this method has no effect.

Return

Content — the detached node


getParentElement()

Gets the node's parent Element node. If the node does not have a parent, this method returns null .

Return

Element — the parent Element node


getText()

Gets the text value of the Text node.

Return

String — the text value of the Text node


getValue()

Gets the text value of all nodes that are direct or indirect children of the node, in the order they appear in the document.

Return

String — the text value of all nodes that are direct or indirect children of the node


setText(text)

Sets the text value of the Text node.

Parameters

Name Type Description
text
String the text value to set

Return

Text — the Text node, for chaining