2010-03-30 123 views
2

值如何在此添加CDATA到ViolationInfo以下XMLCDATA在XML

<Violations ViolationNo="1" ViolationCD="10G" ConditionCode="" SectionCd="NYCHC 81.35" severity="0" ViolationInfo="Cold holding equipment not properly maintained in that two door reach-in refrigerator in kitchen observed holding potentially hazardous milk and operating at an internal temperature of 48°F.. All potentially hazardous foods were discarded as per violation 2G" Point="5" Occurence="0" ViolationDate="2/17/2010 7:58:00 AM"></Violations> 

当我试图如图所示,下面放我收到一个错误说不能有<在价值

<![CDATA[Facility conditions conducive to the existence of pest life in that several holes, approximately 2-3 inches in diameter noted in ceiling throughout rear food storage area and throughout basement.]]> 
+0

CDATA不会在节点属性中工作,但在节点值中完全可以接受。 – 2018-02-09 14:49:16

回答

-1

您不能将CDATA部分放入值中,也不是有意义的 - 值只能包含文本数据,您无需将其包装在CDATA部分中。

+0

但是,当我在文本中有一个度符号时,它会抛出错误说无效字符。 – acadia 2010-03-30 16:04:25

+0

@acadia:使文件使用Unicode编码。 – kennytm 2010-03-30 16:05:13

+0

错误答案。你可以在节点值周围有一个CDATA包装器。你不能把它作为一个属性值。 – 2018-02-09 14:39:11

1

删除CDATA并转义属性文本或将违规信息移至其自己的标记。

<Violations> 
<ViolationInfo><![CDATA[Facility conditions conducive to the existence of pest life in that several holes, approximately 2-3 inches in diameter noted in ceiling throughout rear food storage area and throughout basement.]]></ViolationInfo> 
</Violations> 
+0

这应该是正确的答案。 CDATA不能在XML节点属性中工作,但确实可以用于节点值本身。 – 2018-02-09 14:45:31