473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to detect, if an element string has to be written as CDATA

Hello,

how can i detect, if the text for a XmlElement has to be written as CDATA (i
am using the XmlWriter) instead of a normal string.

For example

<start>
<node1>HelloWorld</node1>
<node2>a>b</node2>
</start>

How can i programmatically detect, that node1 can be written by using
XmlWriter.WriteString and node2 must be written by XmlWriter.WriteCData

Dec 2 '05 #1
4 2311
Hello!
how can i detect, if the text for a XmlElement has to be written as CDATA (i
am using the XmlWriter) instead of a normal string.


There are multiple types that derive from System.Xml.XmlCharacterData -
maybe you can test the type of your XmlNode:

XmlNode n = /* get node */...;

if( n is XmlCDataSection ){ /* <![CDATA[ ... ]]> */ }
else if( n is XmlText ){ /* plain text */ }
else if( n is XmlComment ){ ... }
else if( n is XmlSignificantWhitespace ){ ... }
else if( n is XmlWhitespace ){ ... }
else { /* no text node */ }
--
Pascal Schmitt
Dec 3 '05 #2
>> how can i detect, if the text for a XmlElement has to be written as CDATA
(i am using the XmlWriter) instead of a normal string.


There are multiple types that derive from System.Xml.XmlCharacterData -
maybe you can test the type of your XmlNode:


Sorry, that was not my question.

I'm writing an object modell to xml via XmlWriter.

So, there is no XmlElement-Object.

The only thing that a have is the XmlWriter and a string-field with a value
e.g."Test1" or "a > b".

Now, i need a possibility to decide,
if i had to use XmLWriter.WriteString
or XmlWriter.WriteCData to write this value to the Xml-File.
Dec 3 '05 #3
"Stefan Gentzmer" <StGentzmer_at_gmx.de> wrote:
how can i detect, if the text for a XmlElement has to be written as
CDATA (i am using the XmlWriter) instead of a normal string.


There are multiple types that derive from System.Xml.XmlCharacterData
- maybe you can test the type of your XmlNode:


Sorry, that was not my question.

I'm writing an object modell to xml via XmlWriter.

So, there is no XmlElement-Object.

The only thing that a have is the XmlWriter and a string-field with a
value e.g."Test1" or "a > b".

Now, i need a possibility to decide,
if i had to use XmLWriter.WriteString
or XmlWriter.WriteCData to write this value to the Xml-File.


If the character data contains & or < that must not be interpreted as
markup, then it must be enclosed in a CDATA section.

The example "a>b" does not, so it does not need to be. The > sign is
only interpreted as markup once a < sign has been encountered.

See http://xml.silmaril.ie/authors/cdata/

///Peter

Dec 3 '05 #4
Hello!
The only thing that a have is the XmlWriter and a string-field with a value
e.g."Test1" or "a > b".

Now, i need a possibility to decide,
if i had to use XmLWriter.WriteString
or XmlWriter.WriteCData to write this value to the Xml-File.


Ah - ok. You don't have to decide this - you can always use WriteString,
the XmlTextWriter will do the escaping of &,< and > for you.
--
Pascal Schmitt
Dec 3 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rick | last post by:
Hi.. I've got some code I wrote in PHP that will generate a new argument string for the browser, but the xhtml parser in Firefox and Opera both complain about my use of &var=value pairs. Below...
2
by: Nold Fuchs | last post by:
Hi ! I need to isolate some nodes without CDATA inside, the problem is that I can not get an XPATH to differentiate simple text nodes and CDATA nodes. Sample XML : <nodes> <node>some...
2
by: X. Lee | last post by:
I am creating an xml schema, and I want one of the elements to include html text. Therefore, I want to make that element a CDATA elements so that it can accept html tags as part of it's value. ...
3
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i donīt have a lot of success. Can anybody help me (and understand my english :-))? I have a...
7
by: PeteC | last post by:
I'm working on a web page which has some form elements in it which I need to manipulate using JavaScript. If the element is (for example, in a form called TicketForm) <INPUT...
1
by: unwiseone | last post by:
Hello, Does any know how to specify a value of a DTD element? For example, here's an external DTD that I have: ======================================= <!ELEMENT summercamps (Camp+)>...
1
by: Mike | last post by:
I am consuming a web service hosted by one of our clients. One of the string properties of the object I am creating to pass to their web service is called CustomerName. The XML they re receiving I...
2
by: DesperateDan | last post by:
As the title say, I can't aquire element's value if it hosts sub-elements. Let me explain - My XML looks like this:- <a> <infill>xxxxxx</infill> <SourceEndPoint>testdata <EndPoint> <AliasRef...
1
by: soccerdad | last post by:
I've got a class hierarchy generated from a .xsd schema file using the XSD.EXE tool. One of the elements will have its "inner text" set to a CDATA block. The XSD.EXE tool exposed a "Value" property...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.