Solved

How to Insert CDATA in XML file

Posted on 2003-12-12
3
1,702 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 100 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

718 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