xml-validation

Validate xml created using jaxb against an xsd file

故事扮演 提交于 2019-11-30 09:04:52
I have a xml file created using jaxb. I need to validate it against a xsd document. Is it possible to just do validation without unmarshalling. I need to then print the errors in the xml file. Forhad Yes you can use validator found in java from 1.5. here is the reference doc Apart from it you can use dom based or stream based API to validate your XML document against xsd file. If you wish to use SAX API for your task then hear is the example: try { String schemaLang = "http://www.w3.org/2001/XMLSchema"; SchemaFactory factory = SchemaFactory.newInstance(schemaLang); Schema schema = factory

Validate an XML against an XSD in Java / Getting a hold of the schemaLocation

百般思念 提交于 2019-11-30 07:37:31
问题 How can one validate an XML file using an XSD in Java? We don't know the schema in advance. I would like to be able to get the schemaLocation , download the XSD, cache it and then perform the actual validation. The problem is, that with javax.xml.parsers.DocumentBuilder / DocumentBuilderFactory classes I can't seem to be able to get a hold of the schemaLocation in advance. What's the trick for this? Which classes should I look into? Perhaps there's a more suitable API I can use? The whole

Using .NET to validate XML against a schema

泪湿孤枕 提交于 2019-11-30 07:02:18
I want to test (true or false) whether an arbitrary XML file matches a given schema. For what it's worth, the schema is the Word 2003 WordML schema, which Microsoft defines using a list of about 7 *.xsd files. One of these files also includes the W3C xml.xsd file, by including the following statement: <xsd:import id="xml" namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"></xsd:import> I am using .NET code like the following to do the validation: public static void validate(string filename) { XmlReaderSettings settings = new XmlReaderSettings();

XML Schema Validation : Cannot find the declaration of element

老子叫甜甜 提交于 2019-11-30 03:42:44
I am still a bit new to XML Schema etc. and have been working to develop some XML, Schema and a Stylesheet (XSLT). I have made reasonable progress, but then realized that my Schema had stopped working, so I have taken it back to a simpler non-descript example. Here is my XML: <?xml version="1.0" encoding="UTF-8"?> <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="Test.Namespace" schemaLocation="http://myNameSpace.com Test1.xsd"> <element1 id="001"> <element2 id="001.1"> <element3 id="001.1" /> </element2> </element1> </Root> I have written a Schema that is here: <?xml version=

Difference between <xsd:all> and <xsd:sequence> in schema definition?

邮差的信 提交于 2019-11-29 22:37:23
I am using xsd:all in a complex type. When I miss any mandatory elements while validating it will show all the elements. It will not display the exact missed element. But if I am use xsd:sequence I can get the exact missed element. Is there any difference between these two? xsd:sequence : XML element must be in same order. But xsd:all : XML element may be any order. Madhusudan Joshi <xsd:all> specifies that the child elements can appear in any order. <xsd:sequence> specifies child elements can only appear in the order mentioned. Example for Sequence: <xs:element name="compElement"> <xs

XML (.xsd) feed validation against a schema

为君一笑 提交于 2019-11-29 22:27:09
I have a XML file and I have a XML schema. I want to validate the file against that schema and check if it adheres to that. I am using python but am open to any language for that matter if there is no such useful library in python. What would be my best options here? I would worry about the how fast I can get this up and running. alecxe Definitely lxml . Define an XMLParser with a predefined schema, load the the file fromstring() and catch any XML Schema errors: from lxml import etree def validate(xmlparser, xmlfilename): try: with open(xmlfilename, 'r') as f: etree.fromstring(f.read(),

Is there an xhtml.xsd equivalent available for HTML5?

梦想与她 提交于 2019-11-29 17:37:14
问题 I am developing an appplication based on Mozilla XULRunner. I am using the xhmtl1-strict.xsd provided by the W3C to fetch the attribute. Now the requirement came to add the <video> tag to my application, but my application is not supporting any HTML5 elements or attributes. So, any suggestions? 回答1: HTML5 does not have a doctype definition or an XML schema definition. This is because, although it shares the same syntax as its predecessor HTML 4, HTML5 itself is neither based on SGML nor XML.

Is it possible to use XML Schemas internally, just like DTDs?

三世轮回 提交于 2019-11-29 16:50:22
I have the following XML file which includes internal DTD validation: <?xml version="1.0"?> <!DOCTYPE animals [ <!ELEMENT animals (animal)*> <!ELEMENT animal (skin, noise, eyes, diet, class, weight, special_skill)> <!ELEMENT skin (#PCDATA)> <!ELEMENT noise (#PCDATA)> <!ELEMENT eyes (#PCDATA)> <!ELEMENT diet (#PCDATA)> <!ELEMENT class (#PCDATA)> <!ELEMENT weight (#PCDATA)> <!ELEMENT special_skill (#PCDATA)> <!ATTLIST animal name CDATA #REQUIRED > <!ATTLIST weight unit CDATA "kg"> ]> <animals> <animal name="cow"> <skin> Straight fur </skin> <noise> Moo! </noise> <eyes> 2 </eyes> <diet> Herbivore

XSD allowing both simpleType and complexType content for same element?

瘦欲@ 提交于 2019-11-29 16:35:07
I have a situation where I have different XMLs that will have different types of properties. Sometimes the element HEADER could have just a node or some XMLs could have elements within the HEADER node and values inside. Example 1 ( HEADER with just text): <Details HeaderLabel="DETAILS"> <HEADER Label="Header">2.5%</HEADER> </Details> Example 2 ( HEADER with two child elements): <Details HeaderLabel="DETAILS"> <HEADER Label="Header"> <HEAD Label="H1a">2.88%</HEAD> <HEAD Label="H2b">3.24%</HEAD> </HEADER> </Details> The XSD works as so: This will validate for example 1 : <xs:element name="HEADER

Restrict complexType with attributes in XSD?

不羁的心 提交于 2019-11-29 16:12:34
I'm working with an XSD such as: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="algo"> <xs:complexType> <xs:sequence> <xs:element name="nota" type="t_algo" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="t_algo"> <xs:restriction base="xs:string"> <xs:pattern value="[1][0]|[0-9]" /> </xs:restriction> <xs:attribute name="modul" type="t_modul"/> </xs:complexType> <xs:simpleType name="t_modul"> <xs:restriction base="xs:string"> <xs:pattern