如何在XML中获取不区分大小写的元素 [英] How to get case-insensitive elements in XML

查看:357
本文介绍了如何在XML中获取不区分大小写的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,XML元素类型名称和属性名称
都区分大小写。

As far as I know XML element type names as well as attribute names are case sensitive.

有没有办法获取大小写?不敏感的元素?

Is there a way or any trick to get case insensitive elements?

澄清
通过XSD定义了一种语法,该语法用于某些客户端上载
数据。用户-内容生成器-使用不同的
工具创建XML文件,但其中许多人使用纯文本编辑器或其他工具。有时,当这些人试图上载他们的文件时,会出现不兼容的错误。
尽管将
始终清楚标记是区分大小写的,但他们经常混合使用lowerCase和upperCase标签,这是一个常见错误。

Clarification: A grammar has been defined via XSD which is used for some clients to upload data. The users -the content generators- are creating XML files using different tools but many of them are using plain text editors or whatever. Sometimes when this people are trying to upload their files they get incompatibility errors. It is a common error that they mix lowerCase and upperCase tags although it is was always clear that tags ARE case sensitive.

我可以访问到定义此语法的XSD文件中,我可以对其进行更改。
问题是如何避免这种容易出错的小写/大写标签问题。

I have access to the XSD file which defines this grammar and I can change it. The question is how to avoid this error-prone lower/upper case tags problem.

任何想法吗?

预先感谢!

推荐答案

如果我正确理解了您的问题,那么案例错误只能在两次创建之间得到纠正。并由第三方解析工具上传。

If I understand your problem correctly then the case errors can only be corrected between the creation and the upload by a 3rd party parsing tool.

ie XML文件>根据XSD解析并更正>上载已批准

i.e. XML File > Parsed against XSD and corrected > Upload approved

您可以在运行时通过为客户开发容器应用程序以在其中创建其XML文件的方式来执行此操作。您可以在服务器端编写一个应用程序,该应用程序将接收上载的文件并检查语法。无论哪种方式,您都必须先做出决定,然后再做一些工作!!

You could do this at run-time by developing a container application for your clients to create their XML files in. Alternatively you could write an application on the server side that takes the uploaded file and checks the syntax. Either way you're going to have to make a decision and then do some work!!

很大程度上取决于问题的严重性。如果您在XSD中的不同情况下具有类似的标签,例如而您却收到了,那么您将需要基于节点计数等的复杂解决方案。

A lot depends on the scale of the problem. If you have similar tags in different cases in your XSD e.g. and but you are receiving then you will need a complicated solution based on node counting etc.

如果您纯粹是使用随机大小写,而只包含小写字母的XSD来限制客户标签,那么您应该能够解析文件并将所有标签一次转换为小写。假设标签之间的内容是多大小写的,并且您不能只转换完整的文档。

If you are purely stuck with clients using random cases against an XSD only containing lower case tags then you should be able to parse the files and convert all tags to lower case in one go. This is assuming the content between the tags is multi-case and you can't just convert the full document.

如何执行此操作取决于您所处环境的机制。显然,让客户对自己的提交进行错误检查会更容易。如果这不切实际,那么您将需要在此过程中寻找机会,以便在遇到错误之前将文件转换为正确的格式。

How you do this depends on the mechanics of your situation. Obviously it will be easier to get the clients to error check their own submissions. If this isn't practical then you'll need to identify a window of opportunity in the process which will allow you to convert the file to the correct format before errors are encountered.

这里讨论的方法太多了。这主要取决于您掌握的技能或财务状况。

There are far too many ways to go about this to discuss here. It mainly depends on the skill-sets or finance available to you.

这篇关于如何在XML中获取不区分大小写的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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