?
Solved

How to Insert CDATA in XML file

Posted on 2003-12-12
3
Medium Priority
?
1,704 Views
Last Modified: 2012-05-05
Hi All,

I'm creating XML file using XMLDOM object and VB script. I want all my XML node value to be embedded within the CDATA.

For example here in the following XML file the <enum> node values are embedded inside the CDATA.
---------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<test>
        <enum><![CDATA[test data]]></enum>
        <enum><![CDATA[test data1]]></enum>
</test>
---------------------------------------------------------------------------------------

 Is there any property I need to set to do the same or explicitly I have add the this "![CDATA[]]" while creating the xml node ?

Thanks,
Lilu.

0
Comment
Question by:lilupat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Expert Comment

by:deighc
ID: 9927096
You can specify a node type parameter when you use the createNode method. 4 is the value for a CDATA node. Assuming you have an XML DOM object called xmlDOMObj:

set cdataNode = xmlDOMObj.createNode("nodeName", 4, "<namespace's in here if you want>")
0
 
LVL 28

Expert Comment

by:sybe
ID: 9928376
this code will create a datasection in a node

<%
' oXML is an XML-document (object)
' oNode is a Node of the XMLdocument

Set oDataNode = oXML.createCDATASection("your data here")
oNode.appendChild(oDataNode)
Set oDataNode = Nothing
%>
0
 
LVL 15

Accepted Solution

by:
deighc earned 400 total points
ID: 9928436
Small mistake in my first post: I had the arguments for the createNode method round the way.

set cdataNode = xmlDOMObj.createNode("nodeName", 4, "<namespace's in here if you want>")

should actually be

set cdataNode = xmlDOMObj.createNode(4, "nodeName", "<namespace's in here if you want>")

The suggestions from Sybe and I are functionally identical - in the same way that the createAttribute method achieves the same thing as using createNode(2, "nodeName", "").

The only difference is that the createNode method allows you to specify namespaces if you need them. createAttribute, createCDATASection etc don't allow you to add namespaces.

But Sybe's code should do the trick too.

[I guess the advantage to using createAttribute, createCDATASection etc is that it's more instantly obvious what's happening in your code when you look at it].
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question