?
Solved

How to Insert CDATA in XML file

Posted on 2003-12-12
3
Medium Priority
?
1,703 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

765 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