当前位置: 首页>>代码示例>>Java>>正文


Java XMLStreamReader2.validateAgainst方法代码示例

本文整理汇总了Java中org.codehaus.stax2.XMLStreamReader2.validateAgainst方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader2.validateAgainst方法的具体用法?Java XMLStreamReader2.validateAgainst怎么用?Java XMLStreamReader2.validateAgainst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.stax2.XMLStreamReader2的用法示例。


在下文中一共展示了XMLStreamReader2.validateAgainst方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWsdlValidation

import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
public void testWsdlValidation() throws Exception {
	String runMe = System.getProperty("testWsdlValidation");
	if (runMe == null || "".equals(runMe)) {
		return;
	}
	XMLInputFactory2 factory = getInputFactory();
	XMLStreamReader2 reader = (XMLStreamReader2) factory.createXMLStreamReader(getClass().getResourceAsStream("test-message.xml"), "utf-8");
	QName msgQName = new QName("http://server.hw.demo/", "sayHi");
	while (true) {
		int what = reader.nextTag();
		if (what == XMLStreamConstants.START_ELEMENT) {
			if (reader.getName().equals(msgQName)) {
				reader.validateAgainst(schema);
			}
		} else if (what == XMLStreamConstants.END_ELEMENT) {
			if (reader.getName().equals(msgQName)) {
				reader.stopValidatingAgainst(schema);
			}
		} else if (what == XMLStreamConstants.END_DOCUMENT) {
			break;
		}
	}
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:24,代码来源:TestWsdlValidation.java

示例2: verifyFailure

import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void verifyFailure(String xml, XMLValidationSchema schema, String failMsg,
                             String failPhrase, boolean strict) throws XMLStreamException
{
    XMLStreamReader2 sr = constructStreamReader(getInputFactory(), xml);
    sr.validateAgainst(schema);
    try {
        while (sr.hasNext()) {
            /* int type = */sr.next();
        }
        fail("Expected validity exception for " + failMsg);
    } catch (XMLValidationException vex) {
        String origMsg = vex.getMessage();
        String msg = (origMsg == null) ? "" : origMsg.toLowerCase();
        if (msg.indexOf(failPhrase.toLowerCase()) < 0) {
            String actualMsg = "Expected validation exception for "
                + failMsg + ", containing phrase '" + failPhrase
                + "': got '" + origMsg + "'";
            if (strict) {
                fail(actualMsg);
            }
            warn("suppressing failure due to MSV bug, failure: '"
                 + actualMsg + "'");
        }
        // should get this specific type; not basic stream exception
    } catch (XMLStreamException sex) {
        fail("Expected XMLValidationException for " + failMsg
             + "; instead got " + sex.getMessage());
    }
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:30,代码来源:BaseValidationTest.java

示例3: testFullValidationOk

import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
public void testFullValidationOk() throws XMLStreamException
{
    String XML = "<root attr='123'><leaf /></root>";
    XMLValidationSchema schema = parseDTDSchema(SIMPLE_DTD);
    XMLStreamReader2 sr = getReader(XML);
    sr.validateAgainst(schema);
    while (sr.next() != END_DOCUMENT) { }
    sr.close();
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:10,代码来源:TestDTD.java

示例4: testFullValidationIssue23

import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
public void testFullValidationIssue23() throws XMLStreamException
{
    final String INPUT_DTD = "<!ELEMENT FreeFormText (#PCDATA) >\n"
            +"<!ATTLIST FreeFormText  xml:lang CDATA #IMPLIED >\n"
            ;
    String XML = "<FreeFormText xml:lang='en-US'>foobar</FreeFormText>";
    XMLInputFactory f = getInputFactory();

    /*
    Resolver resolver = new XMLResolver() {
        @Override
        public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) {
            return new StringReader(DTD);
        }
    };
    f.setXMLResolver(resolver);
    */

    XMLValidationSchemaFactory schemaFactory =
            XMLValidationSchemaFactory.newInstance(XMLValidationSchema.SCHEMA_ID_DTD);
    XMLValidationSchema schema = schemaFactory.createSchema(new StringReader(INPUT_DTD));
    XMLStreamReader2 sr = (XMLStreamReader2)f.createXMLStreamReader(
            new StringReader(XML));

    sr.validateAgainst(schema);
    while (sr.next() != END_DOCUMENT) {
        /*
        System.err.println("Curr == "+sr.getEventType());
        if (sr.getEventType() == CHARACTERS) {
            System.err.println(" text: "+sr.getText());
        }
        */
    }
    sr.close();
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:36,代码来源:TestDTD.java

示例5: testPartialValidationOk

import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
/**
 * And then a test for validating starting when stream points
 * to START_ELEMENT
 */
public void testPartialValidationOk()
    throws XMLStreamException
{
    String XML = "<root attr='123'><leaf /></root>";
    XMLValidationSchema schema = parseDTDSchema(SIMPLE_DTD);
    XMLStreamReader2 sr = getReader(XML);
    assertTokenType(START_ELEMENT, sr.next());
    sr.validateAgainst(schema);
    while (sr.next() != END_DOCUMENT) { }
    sr.close();
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:16,代码来源:TestDTD.java

示例6: testGithubIssue2

import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
/**
	 * For problem with MSV: https://github.com/kohsuke/msv/issues/2
	 * 
	 */
    public void testGithubIssue2() throws Exception
    {
        XMLValidationSchema schema = parseW3CSchema(
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:tns='http://MySchema' elementFormDefault='qualified' targetNamespace='http://MySchema' version='1.0'>"
+"<xs:element name='Root' type='tns:Root'/>"
+"<xs:complexType name='Root'>"
+"    <xs:sequence>"
+"      <xs:element minOccurs='0' name='Child' type='xs:anyType'/>"
+"    </xs:sequence>"
+"</xs:complexType>"
+"<xs:complexType abstract='true' name='Child'>"
+"<xs:complexContent>"
+"  <xs:extension base='tns:Base'>"
+"    <xs:sequence/>"
+"  </xs:extension>"
+"</xs:complexContent>"
+"</xs:complexType>"
+"<xs:complexType abstract='true' name='Base'>"
+"<xs:sequence/>"
+"</xs:complexType>"
+"<xs:complexType name='ChildInst'>"
+"<xs:complexContent>"
+"  <xs:extension base='tns:Child'>"
+"    <xs:sequence>"
+"    </xs:sequence>"
+"  </xs:extension>"
+"</xs:complexContent>"
+"</xs:complexType>"
+"</xs:schema>");
        XMLStreamReader2 sr = getReader("<ns11:Root xmlns:ns11='http://MySchema'>"
            +"<ns11:Child xsi:type='ns11:ChildInst' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"
            +"</ns11:Child>"
            +"</ns11:Root>");
        sr.validateAgainst(schema);
        
        try {
            assertTokenType(START_ELEMENT, sr.next());
            assertEquals("Root", sr.getLocalName());
            assertTokenType(START_ELEMENT, sr.next());
            assertEquals("Child", sr.getLocalName());
            assertTokenType(END_ELEMENT, sr.next());
            assertTokenType(END_ELEMENT, sr.next());
            assertTokenType(END_DOCUMENT, sr.next());
        } catch (XMLValidationException vex) {
            fail("Did not expect validation exception, got: " + vex);
        }
        assertTokenType(END_DOCUMENT, sr.getEventType());        
    }
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:53,代码来源:TestW3CSchemaComplexTypes.java


注:本文中的org.codehaus.stax2.XMLStreamReader2.validateAgainst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。