Revision: 12916
http://sourceforge.net/p/foray/code/12916
Author: victormote
Date: 2022-12-22 14:04:15 +0000 (Thu, 22 Dec 2022)
Log Message:
-----------
Validate the namespace and name of the root element.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/Sax2DomParser.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/Sax2DomParser.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/Sax2DomParser.java 2022-12-22 13:39:09 UTC (rev 12915)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/Sax2DomParser.java 2022-12-22 14:04:15 UTC (rev 12916)
@@ -121,9 +121,17 @@
final Attributes attributes) throws SAXException {
if (this.currentElement == null) {
- /* We are trying to parse the root element, which was created when the document was created. Verify that it
- * is the same element name, then process the attributes. */
+ /* We are trying to parse the root element, which was created when the document was created. */
+ /* Verify that it is the same element name. */
+ if (! this.domDocument.getDocumentElement().getNamespaceURI().equals(namespaceURI)) {
+ throw new SAXException("Namespace mismatch on root element.");
+ }
+ if (! this.domDocument.getDocumentElement().getLocalName().equals(localName)) {
+ throw new SAXException("Unexpected root element name: " + localName);
+ }
this.currentElement = this.domDocument.getDocumentElement();
+ /* Process the attributes. The element was created when the document was, but any attributes that it has
+ * could not have been known then. */
processAttributes(this.currentElement, attributes);
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|