CDATA XML and XHTML

Hi,

I was reading as below

if you write a JavaScript code inside a XHTML web page (without using the CDATA section) you have to escape those characters.

Open in new window


  //if (node instanceof Element && node.getNodeName().equalsIgnoreCase("name")) {//did not work in java
   if (node instanceof Element && node.getNodeName().equalsIgnoreCase("name")) {//worked in java

what is CDATa. when we use CDATA section. How CDATA related to XML or XHTML. How XML and XHTML are similar or different. when to use which one. How to write CDATA for given XML. Does SOPA UI needed request within CDATA all the time to get web service response?

Please advise
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zc2Commented:
Please read the following article about the CDATA:
http://www.w3schools.com/xml/xml_cdata.asp

In simple words CDATA is just text part of an XML where you don't want to bother to escape every single mark up character (such as <,>,&)
CDATA has syntax <![CDATA[ some text ]]> and it differs from XML comments <!-- --> in that its content could be extracted by the parser (but all the content of the comments are ignored).
XHTML is an XML, so all the XML rules and requirements applies to XHTML as well.

A Javascript (embedded in XHTML) which code contains a markup character could be one of the following:
1. Just text node inside of the <script> element. Then all the "&" have to be replaced with &amp; (same with "<" and ">" )
2. Enclosed in XML comments <!-- --> . But it will be dropped if you want to parse or do an XSLT processing of the document
3. Be enclosed in a CDATA section. You won't need to escape the mark up characters individually and the content won't be dropped on parsing.
0
gudii9Author Commented:
3. Be enclosed in a CDATA section. You won't need to escape the mark up characters individually and the content won't be dropped on parsing.

is JSP(java server pages similar to CDATA where we write html inside java using different things like scriptlets like

<!=
<%

etc
If there is XML why we need XHTML again. please advise
0
zc2Commented:
I'm not familiar with JSP, but I believe they (as well as the classic ASP) are not XML, so there are different rules of escaping things.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

zc2Commented:
XML is a common formatting (or syntax) standard with a great number of different implementations, each of them has its own set of tag names and its own purpose. XHTML is one of them. The purpose of XHTML is be rendered by a web browser and be able to be read by an XML parser (regular HTML can not be read by an XML parser, because in general, it's not well-formed (special characters are not escaped, some tags might be not closed, etc.)
0
F IgorDeveloperCommented:
XML is a generic strict markup language.  XHTML uses a strict syntax from XML, but using HTML tags

The following code is only valid in HTML : SCRIPT content with special chars (& > < ) are valid

<SCRIPT type="text/javascript">

if ( var1 == 1 && var2 ==2 ) var3=0;

</SCRIPT>

Open in new window


To make this code "XHTML valid" you need to use CDATA delimiters to allow free code into the content tag (content is not parsed as XML/XHTML):

<SCRIPT type="text/javascript"><![CDATA[

if ( var1 == 1 && var2 ==2 ) var3=0;

]]></SCRIPT>

Open in new window


Generally, in XML / XHTML you need to follow the XML syntax rules  to avoid parsing errors.
http://www.w3schools.com/xml/xml_syntax.asp
0
gudii9Author Commented:
SOAP UI  wev service requests cannot take XML but only takes xHTML as request? please advise
0
F IgorDeveloperCommented:
SOAPUI request are written in XML format using the SOAP XML rules and format given by the target web service (defined in a WSDL document )

You can try using soap ui with public web services and see the format in auto-generated requests:
Eg: http://www.w3schools.com/webservices/tempconvert.asmx?WSDL
0
gudii9Author Commented:
SOAP XML rules and format given by the target web service (defined in a WSDL document )

where it is given in below wsdl?

http://www.w3schools.com/webservices/tempconvert.asmx?WSDL

please advise
0
F IgorDeveloperCommented:
The WSDL parsing and convertion to request is a complex parsing task.
Soap UP generate the request based on WSDL parsing, you can see the results when you add a WSDL project and show the "Interface viewer" where you can see the structured WSDL content , ant then get the generated requests.

Generally, a WSDL defines:

Bindings (<wsdl:binding> elements) with available service names , with available actions/operations (<wsdl::operation>)

Ports (<wsdl:portType>) to define input/output messages (<wsdl:input>,<wsdl:output>)  for each operations <wsdl:operation>

Messages (<wsdl:message>) with each parameter used <wsdl:part>


So, the request generation is a combination of data from a selected binding/operation, then finding the output message from the related port/operation, and then generating the request parameters from the selected message

You could try an online WSDL analyzer if you are interested in parsing WSDL definitions
https://www.wsdl-analyzer.com/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.