Ways to read CDATA

Source: Internet
Author: User
Tags cdata xsl

Test.xml:
<root>
<child>
Only text
<! [Cdata[a CDATA text]]>
</child>
</root>

Because the XML Query language supports XSL Patterns and is the default query language for versions prior to MSXML 4.0, you can do so in the version of MSXML 3.0:

var xmldoc=new activexobject ("MSXML2"). domdocument.3.0 ");
Xmldoc.load ("Test.xml");

var root=xmldoc.documentelement;
var node=root.selectsinglenode ("/root/child/cdata ()"); CDATA () not supported in//xpath ()
alert (Node.text);

Because 4.0 no longer supports XSL Patterns, the only way to get CDATA is to:

var node=root.selectsinglenode ("/root/child");
alert (Node.childnodes[1].text);

If more than 4.0, what API can be directly obtained CDATA value, please leave a comment to me tell me:)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.