2010-03-30 110 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