This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi-xmlbeans.git
The following commit(s) were added to refs/heads/trunk by this push:
new d69d2631 test that root xsi:type and xsi:nil errors are still reported
by ValidatingXMLStreamReader (#162)
d69d2631 is described below
commit d69d263161efebfde560aa7d47a5c7863da281e0
Author: PJ Fanning <[email protected]>
AuthorDate: Sat Nov 7 11:12:59 2026 +0100
test that root xsi:type and xsi:nil errors are still reported by
ValidatingXMLStreamReader (#162)
Follow-up to #152, which moved the root element's xsi:type and xsi:nil
checks from the document-type BEGIN to the element BEGIN. Add negative
cases showing the checks moved rather than disappeared: a non-derived
xsi:type (cvc-elt.4.3a) and xsi:nil on a non-nillable root (cvc-elt.3.1).
Share the stream-draining loop between the root xsi tests.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../checkin/ValidatingXMLStreamReaderTests.java | 49 +++++++++++++++-------
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git
a/src/test/java/ValidatingXSRTests/checkin/ValidatingXMLStreamReaderTests.java
b/src/test/java/ValidatingXSRTests/checkin/ValidatingXMLStreamReaderTests.java
index f62f5513..652ccc29 100755
---
a/src/test/java/ValidatingXSRTests/checkin/ValidatingXMLStreamReaderTests.java
+++
b/src/test/java/ValidatingXSRTests/checkin/ValidatingXMLStreamReaderTests.java
@@ -433,24 +433,44 @@ public class ValidatingXMLStreamReaderTests {
void testXsiAttributesOnRootElement(String doc) throws Exception {
// xsi:type and xsi:nil on the root element apply to the root element,
// not to the document type the validator is started with
- XMLStreamReader xsr =
XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(doc));
- Collection<XmlError> errors = new ArrayList<>();
-
- ValidatingXMLStreamReader valXsr = new ValidatingXMLStreamReader();
- valXsr.init(xsr, false, null, rootXsiLoader(), null, errors);
+ List<XmlError> errors = validateWithRootXsiLoader(doc);
+ assertTrue(errors.isEmpty(), errors.toString());
+ }
- while (valXsr.hasNext()) {
- valXsr.next();
- }
+ @Test
+ void testXsiTypeOnRootElementIsValidated() throws Exception {
+ assertSingleRootXsiError(
+ "<i xmlns='urn:t' xmlns:t='urn:t'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='t:small'>9</i>",
+ XmlErrorCodes.DATATYPE_MAX_INCLUSIVE_VALID);
+ }
- assertTrue(valXsr.isValid(), errors.toString());
+ @Test
+ void testXsiTypeOnRootElementNotDerived() throws Exception {
+ // the xsi:type check moved to the root element's BEGIN; it must still
reject
+ // a type that is not derived from the element's declared type
+ assertSingleRootXsiError(
+ "<h xmlns='urn:t' xmlns:t='urn:t'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='t:small'/>",
+ XmlErrorCodes.ELEM_LOCALLY_VALID$XSI_TYPE_NOT_DERIVED);
}
@Test
- void testXsiTypeOnRootElementIsValidated() throws Exception {
- String doc = "<i xmlns='urn:t' xmlns:t='urn:t'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='t:small'>9</i>";
+ void testXsiNilOnNonNillableRootElement() throws Exception {
+ // the xsi:nil check moved to the root element's BEGIN; it must still
reject
+ // xsi:nil on an element that is not nillable
+ assertSingleRootXsiError(
+ "<i xmlns='urn:t'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'/>",
+ XmlErrorCodes.ELEM_LOCALLY_VALID$NOT_NILLABLE);
+ }
+
+ private static void assertSingleRootXsiError(String doc, String
expectedCode) throws Exception {
+ List<XmlError> errors = validateWithRootXsiLoader(doc);
+ assertEquals(1, errors.size(), errors.toString());
+ assertEquals(expectedCode, errors.get(0).getErrorCode());
+ }
+
+ private static List<XmlError> validateWithRootXsiLoader(String doc) throws
Exception {
XMLStreamReader xsr =
XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(doc));
- Collection<XmlError> errors = new ArrayList<>();
+ List<XmlError> errors = new ArrayList<>();
ValidatingXMLStreamReader valXsr = new ValidatingXMLStreamReader();
valXsr.init(xsr, false, null, rootXsiLoader(), null, errors);
@@ -459,9 +479,8 @@ public class ValidatingXMLStreamReaderTests {
valXsr.next();
}
- assertFalse(valXsr.isValid());
- assertEquals(1, errors.size(), errors.toString());
- assertEquals("cvc-maxInclusive-valid",
errors.iterator().next().getErrorCode());
+ assertEquals(errors.isEmpty(), valXsr.isValid(), errors.toString());
+ return errors;
}
private static SchemaTypeLoader rootXsiLoader() throws XmlException {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]