How to create a CDATA Section node in XML

In this articles I am going to explain about how to create a CDATA Section node and comment node.
  • 2512

Create a CDATA Section node in XML

  • CDATA Section method is create a new CDATA Section object node in XML DOM, CDATA Section object  supplied text as the argument.
  • In this method we append a new CDATA node.

Example

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="loadxmldoc.html"></script>

</head>

<body>

 

<script type="text/javascript">

    xmlDoc = loadXMLDoc("library.xml");

 

    newCDATA = xmlDoc.createCDATASection("This is DOM");

 

    a = xmlDoc.getElementsByTagName("book")[0];

    a.appendChild(newCDATA);

 

    document.writeIn(a.lastChild.nodeValue);

</script>

</body>

</html>

Define the code

  • "loadxmldoc.html" get the data.
  •  Create a new CDATA section node in this program.
  •  In this method we append a new CDATA node.
  • "This is DOM" print the message.
 Create a comment node in XML

The comment node method is create a new comment node in XML DOM.

In this method we append a new comment node.

Example

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="loadxmldoc.html"></script>

</head>

<body>

 

<script type="text/javascript">

    xmlDoc = loadXMLDoc("library.xml");

 

    newComment = xmlDoc.createComment("This Comment print");

 

    a = xmlDoc.getElementsByTagName("book")[0];

    a.appendChild(newComment);

 

    document.write(a.lastChild.nodeValue);

</script>

</body>

</html>

Define the code

  • "loadxmldoc.html" get the data.
  •  Create a new comment node in this program.
  •  In this method we append a new comment node.

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.