将XML元素复制到String

时间:2012-09-21 15:47:27

标签: c# .net xml vb.net

  

可能重复:
  XML file copy to a string

 <DETAIL Description='>> Problem:<br><br>CRS750 dumps when panel F is opened<br><br><br>  <br>>> Functional Solution:<br><br>Check cause of the dump and fix it<br><br><br><br>>> Technical Solution:<br><br>Modified CRS750 and added fields WWVTRM and WWCRTP in CRA750F0 record format.<br><br><br><br>>> Related corrections<br><br>None <br><br><br><br>>> Affected Objects<br><br>CRS750 VIEWDEF MAT only' />

我想复制上面的字符串,并使用字符串中的值更新数据库中的表。

但是,由于它包含<br><<,因此抛出以下异常;

'<', hexadecimal value 0x3C, is an invalid attribute character. Line 1, position 902.
像这样的

标签效果很好<DETAIL Objects='MAT: Viewdefinition:CRS750' />请建议

1 个答案:

答案 0 :(得分:1)

您的字符串不是有效的XML,无法将其置于需要XML的位置。

String.Concat不是构造XML的方法。请使用XML API(XmlDocument,XDocument或XmlWriter)来创建XML。

如果你仍然想用string.Concat手工构建XML,请在提问之前证明你已经阅读了XML specification