Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/apache/xmlbeans/impl/store/Cur.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/xmlcursor/checkin/StoreTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 = "<a xmlns:a='aNS'><a:b/></a>";
Expand Down