解析 XML 标签内的 CDATA 的最佳方法是什么

发布于 2024-12-01 00:58:57 字数 697 浏览 0 评论 0原文

我需要在 C# 中解析以下 XML:

<data>
  <customer_id><![CDATA[1414301]]></customer_id>
  <last_modified_date><![CDATA[2011-08-14 11:58:58]]></last_modified_date>
  <customer_first_name><![CDATA[joe]]></customer_first_name>
  <customer_last_name><![CDATA[blow]]></customer_last_name>
</data>

到一个名为 Result 的对象中

public class Result
{
  public int customer_id;
  public string customer_first_name;
  public string customer_last_name;
}

,我试图确定的一件事是如何摆脱

 <![CDATA[]]

并仅解析出常规值。

将此 XML 转换为支持上述 CDATA 语法的对象的最佳方法是什么

i have the following XML that i need to parse in C#:

<data>
  <customer_id><![CDATA[1414301]]></customer_id>
  <last_modified_date><![CDATA[2011-08-14 11:58:58]]></last_modified_date>
  <customer_first_name><![CDATA[joe]]></customer_first_name>
  <customer_last_name><![CDATA[blow]]></customer_last_name>
</data>

into an object called Result

public class Result
{
  public int customer_id;
  public string customer_first_name;
  public string customer_last_name;
}

the one thing that i am trying to determine is how to get rid of the

 <![CDATA[]]

and just parse out the regular values.

What is the best way of converting this XML to the object above that will support the CDATA syntax above

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余生再见 2024-12-08 00:58:57

不确定“解析”是什么意思。如果您使用 XML DOM 解析器(或任何其他类型),那么您可以透明地访问 CDATA 值。

Not sure what you mean by 'parse'. If you use an XML DOM parser (or any other type), then you have transparent access to the CDATA values.

初与友歌 2024-12-08 00:58:57

使用 System.XML?尝试XmlCDataSection

Using System.XML? Try XmlCDataSection?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文