-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for invalid attribute values when it does not conform to the DTD (#…
…128) Fixing invalid attribute values in DTDValidator.
- Loading branch information
1 parent
6adb1e4
commit 5ba99cd
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/java/wstxtest/vstream/TestInvalidAttributeValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package wstxtest.vstream; | ||
|
||
import stax2.BaseStax2Test; | ||
|
||
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.xml.stream.*; | ||
|
||
import org.codehaus.stax2.XMLStreamReader2; | ||
import org.codehaus.stax2.validation.ValidationProblemHandler; | ||
import org.codehaus.stax2.validation.XMLValidationException; | ||
import org.codehaus.stax2.validation.XMLValidationProblem; | ||
import org.codehaus.stax2.validation.XMLValidationSchema; | ||
import org.codehaus.stax2.validation.XMLValidationSchemaFactory; | ||
|
||
public class TestInvalidAttributeValue | ||
extends BaseStax2Test | ||
{ | ||
public void testInvalidAttributeValue() throws Exception | ||
{ | ||
final String DOC = "<root note='note' verbose='yes'/>\n"; | ||
|
||
final String INPUT_DTD = | ||
"<!ELEMENT root ANY>\n" | ||
+"<!ATTLIST root note CDATA #IMPLIED>\n" | ||
; | ||
|
||
XMLInputFactory f = getInputFactory(); | ||
setCoalescing(f, true); | ||
|
||
XMLValidationSchemaFactory schemaFactory = | ||
XMLValidationSchemaFactory.newInstance(XMLValidationSchema.SCHEMA_ID_DTD); | ||
XMLValidationSchema schema = schemaFactory.createSchema(new StringReader(INPUT_DTD)); | ||
XMLStreamReader2 sr = (XMLStreamReader2)f.createXMLStreamReader( | ||
new StringReader(DOC)); | ||
|
||
final List<XMLValidationProblem> probs = new ArrayList<XMLValidationProblem>(); | ||
|
||
sr.validateAgainst(schema); | ||
sr.setValidationProblemHandler(new ValidationProblemHandler() { | ||
@Override | ||
public void reportProblem(XMLValidationProblem problem) | ||
throws XMLValidationException { | ||
probs.add(problem); | ||
} | ||
}); | ||
|
||
assertTokenType(START_ELEMENT, sr.next()); | ||
assertEquals("root", sr.getLocalName()); | ||
|
||
final String verboseValue = sr.getAttributeValue(null, "verbose"); | ||
|
||
assertEquals("yes", verboseValue); | ||
} | ||
} |