Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get case-insensitive elements in 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?

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.

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.

Any idea?

Thanks in advance!

like image 970
Luixv Avatar asked May 15 '09 14:05

Luixv


People also ask

Are XML cases insensitive?

XML tags are case sensitive. All XML elements must be properly nested. All XML documents must have a root element. Attribute values must always be quoted.

Do XML elements need lowercase?

For example, <ROOT>, <Root>, and <root> are three different tags. Although XML doesn't care whether your tag names and other structural elements are uppercase or lowercase, some applications that use XML do care.

Why are XML tags case-sensitive?

All of an XML document is case-sensitive. This is significantly different from HTML and most other SGML applications, where the default was to ignore case. It was done to allow markup in non-Latin-alphabet languages, and to obviate problems with case-folding in writing systems which are inherently caseless.


1 Answers

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.

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

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!!

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.

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.

like image 60
melkisadek Avatar answered Oct 25 '22 09:10

melkisadek