3

Suppose my web service emits XML with "xmlns", "xmlns:xsi" and "xsi:schemaLocation" set to be placeholders that are not valid URIs (like "blahblahblah" for example) and once that service has been used from numerous systems one of the users discovers that his XML parser will not like the placeholder.

Now I have to do something with it. One of the options is to just remove "xmlns", "xmlns:xsi" and "xsi:schemaLocation" attributes.

Will removing them likely break existing users? Would such XML be valid?

rolve
  • 10,083
  • 4
  • 55
  • 75
sharptooth
  • 167,383
  • 100
  • 513
  • 979

2 Answers2

2

If you previously had a xmlns attribute in your document element, it means that all XML elements (with no prefix) were in a namespace. If you now remove that namespace, this is no true anymore and the output of any (namespace-aware) parser changes. And with that, most probably the behavior of the programs working on the parsed data.

Just as an example, using XPath in Java is different if the XML elements are in a namespace: How to query XML using namespaces in Java with XPath?. Although the accepted answer shows a way to use XPath in a namespace-agnostic way, most programs will probably not use this approach.

The XML should still be valid (actually well-formed), you can easily check that in a decent XML editor that supports validation (including Eclipse for example). But because you removed the reference to the Schema, validation will only cover basic XML rules (as I said, the well-formedness), not the rules set up by the Schema.

So in short, yes, you may break your clients but yes, the XML would (probably) still be valid.

Community
  • 1
  • 1
rolve
  • 10,083
  • 4
  • 55
  • 75
  • Two out of three correct. The namespacectomy described by the OP should indeed leave the XML well formed, and it is indeed likely to break downstream consumers of the data. But the data will almost certainly no longer be valid, because *valid* doesn't mean "allowed by the XML spec"; it means "correct against a schema or DTD". It's theoretically possible for a schema to accept both namespace-qualified input and unqualified input, but very few schemas do. – C. M. Sperberg-McQueen Sep 26 '12 at 15:33
  • Thanks for the clarification. As indicated by "(actually *well-formed*)", I used the term "valid" rather informally here. – rolve Sep 26 '12 at 16:19
1

The XML files will still be well-formed if they were well-formed previously. Validity doesn't really apply because you weren't pointing to a proper schema document with the xsi:location attribute anyway.

In fact, the user complaining is probably the only one who is trying to validate your files. The rest of your consumers were doing fine with the placeholders. They may fare just as well without those attribute specifications altogether, unless they have software specifically customized to "recognize" your blahblahblah inventions.

arayq2
  • 2,502
  • 17
  • 21