Solved

How to Insert CDATA in XML file

Posted on 2003-12-12
3
1,697 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
  • 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now