问题描述
我的目标是在java中使用XSD架构进行独立的HTML 5标记验证。
My goal is to do standalone HTML 5 Markup validation with an XSD schema in java.
下面我将介绍我的方法。
任何帮助都表示赞赏 - 如果有其他或更好的方法可以做到这一点。
In the following I describe my approach. Any help is appreciated -- also if there is an alternative or better way to do this.
发布了。
Trang [3]是一个用于不同XML模式语言的开源转换器,应该能够从Relax NG转换为XSD。使用WHATTF架构,可以按如下方式调用转换器:
Trang [3], is an open-source converter for different XML schema languages and should be able to convert from Relax NG to XSD. With the WHATTF schema, a trang converter call can be made as follows:
$ java -jar ./trang.jar ./whattf/syntax/relaxng/html5.rnc html5.xsd
然而,trang会产生以下许多游荡不正确的类型转换:
However, trang produces many of the following wanrnings on incorrect type conversion:
whattf/syntax/relaxng/applications.rnc:265:51: warning: cannot convert datatype library "http://whattf.org/datatype-draft"; using datatype "string"
[...]
我认为trang工作正常,需要将pluggable-datatypes [4]传递给jing。 Jing [5]
是一个Relax NG验证器,我认为它是由trang使用的。
I think for trang to be working, one needs to pass pluggable-datatypes [4] to jing. Jing [5] is a Relax NG validator and I think it used by trang.
在whattf / syntax / relaxng / datatype文件夹中,提供了这些pluggable-datatypes的java实现。因此,我创建了一个html5-datatypes.jar并将其添加到trangs类路径中,如下所示:
In the whattf/syntax/relaxng/datatype folder a java implementation for these pluggable-datatypes is provided. Thus I created a html5-datatypes.jar and added it to trangs classpath as follows:
$ java -cp ./html5-datatypes.jar -jar ./trang.jar ./whattf/syntax/relaxng/html5.rnc html5.xsd
但是,这会导致相同的错误。
However, this results in the same errors.
除此之外,使用创建的XSD文件和 javax.xml.validation.Validator
如下:
Beyond that, using the created XSD files with the javax.xml.validation.Validator
as follows:
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = schemaFactory.newSchema( new File("html5.xsd") );
Validator validator = schema.newValidator();
validator.validate( new StreamSource( new File("example.html") ) );
产生异常:
org.xml.sax.SAXParseException: cos-element-consistent: Error for type 'time.inner'. Multiple elements with name 'script', with different types, appear in the model group.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XSConstraints.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.XSConstraints.fullSchemaChecking(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:594)
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:610)
[3] thaiopensource.com/relaxng/trang.html
[3] thaiopensource.com/relaxng/trang.html
[4] thaiopensource.com/relaxng /pluggable-datatypes.html
[4] thaiopensource.com/relaxng/pluggable-datatypes.html
[5] thaiopensource.com/relaxng/jing.html
[5] thaiopensource.com/relaxng/jing.html
推荐答案
Web上似乎有一些XHTML 5 XSD。例如,有一个开源的XHTML 5架构:
There seem to be some XHTML 5 XSDs around in the Web. For instance, there was an open-source XHTML 5 Schema at: http://www.xmlmind.com/xmleditor/download.shtml
这篇关于使用XSD / trang HTML进行Java HTML 5验证5放宽NG到XSD的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!