将 xml 属性双引号转换为单引号(需要实用程序,pref java)
我有一个非常烦人的问题。我的公司使用 Castor 来编组和解组 xml。我正在与另一家公司集成,看起来他们的 xml 解析器要求属性用单引号引起来。 Castor 被硬编码为使用双引号。哎呀!
有谁知道有一个实用程序(最好是java库)可以安全地转换这些引号?
简单的正则表达式不是首选解决方案,因为当尝试修复属性值本身内的转义双引号和未转义单引号时,它会变得极其复杂且存在错误。另外,如果这样的实用程序已经存在,我宁愿不花时间编写和调试。
谢谢 阿拉斯泰尔
I have a seriously annoying problem. My company uses castor to marshall and unmarshall xml. I'm working on integrating with another company and it looks like their xml parser requires attributes to be single-quoted. Castor is hardcoded to use double quotes. Whoops!
Does anyone know of a utility (preferrably a java library) which can safely convert these quotes?
Simple regexps are not a preferred solution because it will become extremely complicated and buggy when trying to fix escaped double quotes and unescaped single quotes inside the attribute values themselves. Plus I'd rather not spend the time writing and debugging such a util if one already exists.
Thanks
Alastair
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您不会找到一个现成的序列化器可以做到这一点。我的建议(如果您无法说服您的业务合作伙伴采用 XML 标准)是找到一个开源序列化程序(例如 Saxon 序列化程序)并对其进行自定义。
I don't think you're going to find an off-the-shelf serializer that does this. My suggestion (if you can't persuade your business partner to adopt XML standards) would be to find an open-source serializer (e.g. the Saxon one) and customize it.