在XML中合法使用CDATA [英] Legally use CDATA in XML
本文介绍了在XML中合法使用CDATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个XML分析器阻塞的XML文件。
其中一部分是:
I have an XML file which XML parser choke on. A part of it is :
<closedDeal><customer><![CDATA[ABC ]]></customer></closedDeal>
我得到的错误是
The literal string ']]>' is not allowed in element content. Error processing resource
使用CDATA的正确方法是什么?
我需要CDATA,因为数据是从Excel中读取的,并且可能包含ALT + ENTER空格之类的非法字符。
What is the correct way of using CDATA? I need CDATA because the data is read from Excel, and could contain illegal character such as ALT+ENTER whitespace.
请帮助。
谢谢。
Please help. Thanks.
推荐答案
您正在使用什么解析器?您显示的示例绝对是有效的XML。例如,在.NET中,我成功解析了以下XML:
What parser are you using? The sample you showed is definitely a valid XML. For example in .NET I successfully parsed this XML :
<?xml version="1.0" encoding="utf-8" ?>
<closedDeal>
<customer><![CDATA[ABC ]]></customer>
</closedDeal>
使用以下代码:
using System;
using System.Xml.Linq;
using System.Xml.XPath;
public class Program
{
static void Main(string[] args)
{
var doc = XElement.Load("test.xml");
doc.XPathSelectElement("//customer");
Console.WriteLine(doc.Value);
}
}
这篇关于在XML中合法使用CDATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文