建议的处理无效XML的方法 [英] Suggested method for dealing with invalid XML

查看:230
本文介绍了建议的处理无效XML的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Delphi XE2将程序与第三方服务集成。我遇到的问题是该服务没有在他们发送给我的XML文档中转义它们的任何值。

I'm trying to integrate a program with a 3rd party service using Delphi XE2. The problem I'm running into is that the service isn't escaping any of their values in the XML documents they send me.

这是他们的示例 xml文档之一

This is one of their "sample" xml documents

<plans type="array">
  <plan>
    <id type="integer">1</id>
    <series-title>A New Plan</series-title>
    <dates>January 16 & 17, 2010</dates>
   <plan-title>A New Plan For Your Family</plan-title>
 </plan>
 ...
</plans>

我最初的计划是将所有数据包装在 CDATA 标记,但这似乎不是理想的解决方案。

My original plan was just to wrap all the data in CDATA tags, but that doesn't seem like an ideal solution.

我还考虑过搜索& 字符并将其替换为&放大器; ,但是它不会转义任何用户输入,包括< > 并搜索并替换每个无效的xml字符也听起来像是个坏主意。

I also thought about searching for the & character and replacing it with &amp; but it doesn't escape ANY of the user input, including < and > and doing a search and replace for every invalid xml character sounds like a bad idea as well.

关于如何处理无效xml的任何建议文档?

Any suggestions on how I should go about dealing with the invalid xml documents?

推荐答案

从拒绝将这些文档称为 XML开始-它们不是XML。

Start by refusing to refer to these documents as "XML" - they aren't XML.

说服您的供应商,很多人已经采用XML并从中受益,如果这样做也很好。

Persuade your supplier that many people have adopted XML and are getting benefits from it, and it would be a good idea if they did so too.

如果您的供应商给他们留下了向您发送XML的印象,请对它们进行正确处理。几乎是XML并没有帮助。就像向您发送了无法编译的Java代码。

If your supplier is under the impression that they are sending you XML, put them right. Being almost XML doesn't help. It's like sending you Java code that won't compile.

这篇关于建议的处理无效XML的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆