diff --git a/src/main/java/org/apache/xmlbeans/impl/store/Cur.java b/src/main/java/org/apache/xmlbeans/impl/store/Cur.java index 241508f6f..808d8b26b 100755 --- a/src/main/java/org/apache/xmlbeans/impl/store/Cur.java +++ b/src/main/java/org/apache/xmlbeans/impl/store/Cur.java @@ -2923,10 +2923,12 @@ public void attr(QName name, String value) { text(value, 0, value.length()); end(); if (isId) { + _locale.enter(); Cur c1 = x.tempCur(); c1.toRoot(); Xobj doc = c1._xobj; c1.release(); + _locale.exit(); if (doc instanceof DocumentXobj) { ((DocumentXobj) doc).addIdElement(value, x._parent.getDom()); diff --git a/src/test/java/xmlcursor/checkin/StoreTests.java b/src/test/java/xmlcursor/checkin/StoreTests.java index d869e91d0..a94c09df4 100755 --- a/src/test/java/xmlcursor/checkin/StoreTests.java +++ b/src/test/java/xmlcursor/checkin/StoreTests.java @@ -18,6 +18,7 @@ import org.apache.xmlbeans.*; import org.apache.xmlbeans.XmlCursor.TokenType; import org.apache.xmlbeans.XmlCursor.XmlBookmark; +import org.apache.xmlbeans.impl.store.Locale; import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; @@ -26,6 +27,7 @@ import org.junit.jupiter.params.provider.ValueSource; import org.xml.sax.*; import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.AttributesImpl; import xmlcursor.common.Common; import javax.xml.namespace.QName; @@ -1950,6 +1952,38 @@ void testSaxParser() throws Exception { assertEquals(x1.xmlText(), x2.xmlText()); } + @Test + void testSaxHandlerIdDetection() throws SAXException{ + final XmlOptions emptyXmlOptions = new XmlOptions(); + final String schemaUri = "http://example.com/schema"; + + final Locale loc = Locale.getLocale(null, null); + final AttributesImpl attrs = new AttributesImpl(); + + // The QName must be "id" as that's now enough for an attribute to be treated as an ID + attrs.addAttribute( + schemaUri, + "localIgnored", + "id", + "CDATA", + "anId" + ); + + loc.getSchemaTypeLoader().newXmlSaxHandler(null, emptyXmlOptions); + ContentHandler xmlSaxHandler = Locale.newSaxHandler( + loc.getSchemaTypeLoader(), + null, + emptyXmlOptions + ).getContentHandler(); + + xmlSaxHandler.startElement( + schemaUri, + "localIgnored", + "sa:someName", + attrs + ); + } + @Test void testAdditionalNamespaces() throws Exception { String xml = "";