xsd-validation

stax xml validation

谁说胖子不能爱 提交于 2019-11-26 19:31:45
问题 I know I can validate xml-file when I use sax. But can I validate when I use Stax? 回答1: There are two ways of XML validation possible with SAX and DOM: validate alone - via Validator.validate() validate during parsing - via DocumentBuilderFactory.setSchema() and SAXParserFactory.setSchema() With StAX, validation is possible , but only the first way of doing it. You can try something like this: import javax.xml.validation.*; import javax.xml.transform.stax.*; import javax.xml.stream.*; import

What does elementFormDefault do in XSD?

会有一股神秘感。 提交于 2019-11-26 15:11:24
What does elementFormDefault do, and when should it be used? So I found some definitions for elementFormDefault values: qualified - elements and attributes are in the targetNamespace of the schema unqualified - elements and attributes do not have a namespace So from that definition I would think that if a schema is set to qualified then why must you prefix the type with the namespace? And what are the scenarios that you would even have one set to unqualified for that matter? I tried Googling, but all I got were a couple W3C pages that were extremely hard to understand. This is the file I am

Does JAXB support xsd:restriction?

痞子三分冷 提交于 2019-11-26 08:16:47
问题 <xs:element name=\"age\"> <xs:simpleType> <xs:restriction base=\"xs:integer\"> <xs:minInclusive value=\"0\"/> <xs:maxInclusive value=\"120\"/> </xs:restriction> </xs:simpleType> </xs:element> So I want it to get converted to Java code like this: public void setAge(int age){ if(age < 0 || age > 120){ //throw some exception } //setting the age as it is a valid value } Is it possible in JAXB? Had seen some WebService Client stub generator doing this maybe axis2 webservice but not sure. 回答1: The

XML Validation with XSD in Visual Studio IDE

只愿长相守 提交于 2019-11-26 07:57:27
问题 I know I have done this before, but it isn\'t working today, nor can I find anywhere that explains how to do it. It could be my lack of sleep, but I suspect gremlins. I have an XML document and a directory full of XSD\'s that define it. How do I set the Visual IDE up to notify me of validation failures, and then provide an intellisense list of valid tags and attributes in a given context? What I have tried: I\'ve added the XSD\'s to the project with the XML document. I\'ve added the XSD\'s to

Require XML element in XSD when another element has certain value?

我只是一个虾纸丫 提交于 2019-11-26 04:27:42
问题 I need a required attribute or element only if a specific value of an enumeration is chosen. Example below: <xs:element name=\"TYPE\" type=\"TestEnum\" /> <!-- // This Element should only required when TYPE = INTERNATIONAL --> <xs:element name=\"IBAN\"/> </xs:complexType> <xs:simpleType name=\"TestEnum\"> <xs:restriction base=\"xs:string\"> <xs:enumeration value=\"NATIONAL\"/> <xs:enumeration value=\"INTERNATIONAL\"/> </xs:restriction> </xs:simpleType> 回答1: XSD 1.1 Here's how use xs:assert to

How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?

帅比萌擦擦* 提交于 2019-11-26 02:20:09
I found some tips for this problem, but still didn't help me. Here is my XML <?xml version="1.0" encoding="UTF-8"?> <work xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.w3.org/2001/XMLSchema-instance" tns:schemaLocation="myXSDSchema.xsd"> <tns:Objects> <tns:Object Name=":" Location=":"> </tns:Object> </tns:Objects> </work> Here is my XSD file: <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns = "http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> (some checks) </schema> My XSD file is located in the same folder as the XML. How to link these 2 files? How

How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?

自作多情 提交于 2019-11-26 01:08:52
问题 I found some tips for this problem, but still didn\'t help me. Here is my XML <?xml version=\"1.0\" encoding=\"UTF-8\"?> <work xmlns=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns=\"http://www.w3.org/2001/XMLSchema-instance\" tns:schemaLocation=\"myXSDSchema.xsd\"> <tns:Objects> <tns:Object Name=\":\" Location=\":\"> </tns:Object> </tns:Objects> </work> Here is my XSD file: <schema xmlns=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns = \"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\

How to make type depend on attribute value using Conditional Type Assignment

◇◆丶佛笑我妖孽 提交于 2019-11-26 00:30:01
问题 I have an XML file like this <listOfA> <a type=\"1\"> <name></name> <surname></surname> </a> <a type=\"2\"> <name></name> <id></id> </a> </listOfA> I\'d like to make an XSD, so that if the value of the attribute \"type\" is 1, the name and surname elements must be present, and when it\'s 2, name and id must be there. I tried to generate the XSD in XSD schema generator, but it made the surname and id element minOccurs=0. How could I make it work? 回答1: You can do this using XSD 1.1's