xml-validation

cvc-complex-type.2.3: Element 'group' cannot have character [children], because the type's content type is element-only

梦想与她 提交于 2020-01-15 08:26:12
问题 I need to create XML from this XSD: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="group"> <xs:complexType> <xs:sequence> <xs:element name="person" minOccurs="5" maxOccurs="20" type="xs:string"/> </xs:sequence> <xs:attribute name="name" use="required" type="xs:string"/> </xs:complexType> </xs:element> </xs:schema> Here is the XML I've tried: <?xml version="1.0" ?> <group name="abcd"> xmlns="www.example.org" xmlns:xsi="http:/

Linux command line tool validating XSD 1.1?

梦想的初衷 提交于 2020-01-15 07:09:33
问题 Is there any command line tool that validates XML against a XSD version 1.1 ? Xmllint does not validate version 1.1. 回答1: XSD 1.1 is currently supported by Saxon and by Xerces J. Both should run without trouble under Linux. 回答2: I found a handy wrapper around Xerces-J: https://www.dropbox.com/s/939jv39ihnluem0/xsd11-validator.jar java -jar xsd11-validator.jar -sf my.xsd -if my.xml You can update the Xerces-J lib by unzipping the jar, dropping the new Xerces-J in it, then rezipping it to a jar

Define simple type such as xsd:string in a new namespace?

本秂侑毒 提交于 2020-01-15 04:51:07
问题 This should be straight forward but everywhere I look it seems to have information only about complex types. Let's say that I have defined a namespace xmlns:address="http://...." . Now from what I have read it seams like I could do the following: <xsd:element name="street" type="address:sAdd"/> and then define the complex type <xsd:complexType name="sAdd"> . However, I cannot find what happens in the case of a non complex type like a xsd:string . My guess would be something like <xsd:element

validate xml during serialization

痞子三分冷 提交于 2020-01-06 07:13:06
问题 This post https://stackoverflow.com/a/1708614/5333340 gives a solution on how to validate an xml during deserialization. It also says that similar code can be written for serialization, but I was not able to figure it out. Can someone give a hint? I want to do the validation during serialization, so that, if the validation fails at some point, the serialization stops immediately. Based on the linked answer my deserialization code, where validation takes place, looks like this: private static

validate xml during serialization

旧街凉风 提交于 2020-01-06 07:13:06
问题 This post https://stackoverflow.com/a/1708614/5333340 gives a solution on how to validate an xml during deserialization. It also says that similar code can be written for serialization, but I was not able to figure it out. Can someone give a hint? I want to do the validation during serialization, so that, if the validation fails at some point, the serialization stops immediately. Based on the linked answer my deserialization code, where validation takes place, looks like this: private static

Unique value across elements in XSD

与世无争的帅哥 提交于 2020-01-06 06:06:04
问题 I'm trying to enforce a unique value across an element used in multiple complexType elements. For example : <xs:element name="lmt"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element ref="lf" maxOccurs="unbounded"/> <xs:element ref="cdl" maxOccurs="unbounded"/> </xs:choice> </xs:complexType> <xs:unique name="uniquePos"> <xs:selector xpath="./*/pos"/> <xs:field xpath="."/> </xs:unique> </xs:element> <xs:element name="pos"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs

validating XML node over a XSD file

别说谁变了你拦得住时间么 提交于 2020-01-05 09:11:59
问题 I'm trying to validate XML nodes or fragments against an XML schema. I have read this article: Validating xml nodes, not the entire document but the chosen solution doesn't look like to work for me. private void ValidateSubnode(XmlNode node, XmlSchema schema) { XmlTextReader reader = new XmlTextReader(node.OuterXml, XmlNodeType.Element, null); XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; settings.Schemas.Add(schema); settings

How can allowed element values depend on other element values in XSD?

北战南征 提交于 2020-01-05 04:54:13
问题 I have a following task (in simple version): Describe in XSD temperatures. There are min, max and default values. Default should be placed inside of min...max values. How to describe these things with XSD? I mean: Min_Set_Temp [ Integer between 0 and 1000 ] Max Set Temp [ Integer between 0 and 1000 ] Default_Set_Temp [ Integer between Min Set Temp and Max Set Temp] XSD start: <xs:simpleType name="tSetTemperature"> <xs:restriction base="xs:unsignedShort"> <xs:minInclusive value="0"/> <xs

can't compile a W3C-provided XSD schema; can't resolve “id”?

筅森魡賤 提交于 2020-01-04 04:48:06
问题 I'm playing around with an XML schema and trying to produce a simple valid document that uses it. The schema XSD is provided by the W3C, so I can't imagine anything's actually wrong with it. But xmllint on the command line as well as any number of freebie online validators complain about the actual XSD (not my test document) with: The QName value '{http://www.w3.org/XML/1998/namespace}id' does not resolve to a(n) attribute declaration. Note that it can't resolve the id type/name, which is

Nesting XML elements from different namespaces in XSD

烂漫一生 提交于 2020-01-03 19:31:27
问题 Assume that I have an XML schema definition for elements of a namespace that I would like to use as child elements of XML elements within a second namespace. As an example, suppose we have file foo.xsd : <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns="urn:foo-ns" targetNamespace="urn:foo-ns" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="foo" type="fooType"/> <xs:complexType name="fooType"> <xs:attribute name="id" use="required"/> </xs