From 266e837852e0f0e3c8c1ad572b6fc4dbb4ded17b Mon Sep 17 00:00:00 2001 From: Michael Glavassevich Date: Wed, 3 Jul 2013 18:29:43 +0000 Subject: [PATCH] The only legal names in XML 1.0/1.1 documents are 'version', 'encoding' and 'standalone'. Replacing the generic call to the scanner with a specialized method which only allows these legal XML pseudo attribute names. This improves the performance of the XML scanner when it is processing the XML declaration. git-svn-id: https://svn.apache.org/repos/asf/xerces/java/trunk@1499506 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/xerces/impl/XMLScanner.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/org/apache/xerces/impl/XMLScanner.java b/src/org/apache/xerces/impl/XMLScanner.java index 93f1074f90..2c4026a2f2 100644 --- a/src/org/apache/xerces/impl/XMLScanner.java +++ b/src/org/apache/xerces/impl/XMLScanner.java @@ -542,7 +542,7 @@ public String scanPseudoAttribute(boolean scanningTextDecl, // document is until we scan the encoding declaration // you cannot reliably read any characters outside // of the ASCII range here. -- mrglavas - String name = fEntityScanner.scanName(); + String name = scanPseudoAttributeName(); XMLEntityManager.print(fEntityManager.getCurrentEntity()); if (name == null) { reportFatalError("PseudoAttrNameExpected", null); @@ -598,6 +598,35 @@ else if (isInvalidLiteral(c)) { } // scanPseudoAttribute(XMLString):String + /** + * Scans the name of a pseudo attribute. The only legal names + * in XML 1.0/1.1 documents are 'version', 'encoding' and 'standalone'. + * + * @return the name of the pseudo attribute or null + * if a legal pseudo attribute name could not be scanned. + */ + private String scanPseudoAttributeName() throws IOException, XNIException { + final int ch = fEntityScanner.peekChar(); + switch (ch) { + case 'v': + if (fEntityScanner.skipString(fVersionSymbol)) { + return fVersionSymbol; + } + break; + case 'e': + if (fEntityScanner.skipString(fEncodingSymbol)) { + return fEncodingSymbol; + } + break; + case 's': + if (fEntityScanner.skipString(fStandaloneSymbol)) { + return fStandaloneSymbol; + } + break; + } + return null; + } // scanPseudoAttributeName() + /** * Scans a processing instruction. *