There are a couple of "bugs" in the schema location parsing
if the attribute does not contain the expected tokens:
public static String getSchemaLocation(Attributes attrs, String nsUri) { String location = null; String schemaLocation = attrs.getValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "schemaLocation"); if(schemaLocation != null) { StringTokenizer tokenizer = new StringTokenizer(schemaLocation, " \t\n\r"); String ns = tokenizer.nextToken(); while(ns != null) { location = tokenizer.nextToken(); // Comment: Oops no next token if(ns.equals(nsUri)) { break; } ns = tokenizer.nextToken(); } } // Comment: Returns the last "location" even if the namespace didn't match? // Is that intentional? return location; }
public static String getSchemaLocation(Attributes attrs, String nsUri) { String schemaLocation = attrs.getValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "schemaLocation"); if (schemaLocation != null) { StringTokenizer tokenizer = new StringTokenizer(schemaLocation, " \t\n\r"); while (tokenizer.hasMoreTokens()) { String namespace = tokenizer.nextToken(); if (namespace.equals(nsUri) && tokenizer.hasMoreTokens()) return tokenizer.nextToken(); } } return null; }
That is better.