自从我今天更新到GAE 1.7.2.1以来,我在所有jdoconfig.xml文件中都在eclipse中遇到验证错误.
我有默认的jdoconfig.xml内容:
[...]
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
[...]
Run Code Online (Sandbox Code Playgroud)
并且eclipse验证抛出:
Referenced file contains errors (http://java.sun.com/xml/ns/jdo/jdoconfig).
For more information, right click on the message in the Problems View and
select "Show Details..."
Run Code Online (Sandbox Code Playgroud)
点击细节我可以看到一堆如下的行:
s4s-elt-character: Non-whitespace characters are not allowed in schema elements
other than 'xs:appinfo' and 'xs:documentation'. Saw 'var_U = "undefined";'.
Run Code Online (Sandbox Code Playgroud)
在"Saw ......"中的不同行和不同内容
它发生在我开始使用谷歌插件中的"新建Web应用程序项目..."的每个项目中.
所以有人有这个问题吗?任何修复?
我试图在XSD中使用以下内容
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" >
<xs:element name="dimension">
<xs:complexType>
<xs:attribute name="height" type="xs:int"/>
<xs:attribute name="width" type="xs:int"/>
<xs:assert test="@height = @width"/>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
我知道assert/assertion是XML Schema 1.1的一部分,但不是1.0.但是我读过的所有内容都表明两者的名称空间相同:http://www.w3.org/2001/XMLSchema
一个小问题是我用来编写Schema(Microsoft Visual Studio)的程序无法识别'assert'元素,说' 命名空间中的元素complexType(...)具有无效的子元素'assert'.
主要的问题是,当我实际尝试使用xmllint对此模式验证XML时,它会抛出一个错误说
" element assert: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}complexType': The content is not valid. Expected is (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
Run Code Online (Sandbox Code Playgroud)
虽然被指向了1.1名称空间,但xmllint/visual studio却无法识别1.1吗?
背景:
我们正在构建一个应用程序,允许我们的客户以预定义(即我们无法控制)的XML格式提供数据.XSD由第三方提供给我们,我们期望在我们处理它之前收到一个传递模式验证的XML文件.
问题:
我们提供的XSD包括默认和目标命名空间,这意味着如果客户提供的XML文件不包含命名空间,则验证将通过.我们显然不希望他们提供说他们通过但不应该提供的东西,但更大的问题是如果我找不到解决办法,我们需要对每个元素进行额外的检查. XML验证.
问题:
是否可以强制.NET执行验证并忽略提供的XML和XSD上的命名空间.即以某种方式"假设"命名空间被附加.
我到目前为止的解决方案:
示例Xml:
<?xml version="1.0"?>
<xsd:schema version='3.09' elementFormDefault='qualified' attributeFormDefault='unqualified' id='blah' targetNamespace='urn:schemas-blah.com:blahExample' xmlns='urn:blah:blahExample' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
...
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
与命名空间不同
<?xml version="1.0" encoding="UTF-8" ?>
<root xmlns="urn:myCompany.com:blahExample1" attr1="2001-03-03" attr2="google" >
...
</root>
Run Code Online (Sandbox Code Playgroud)
没有命名空间.
<?xml version="1.0" encoding="UTF-8" ?>
<root attr1="2001-03-03" attr2="google" >
...
</root>
Run Code Online (Sandbox Code Playgroud) 第一个问题(善良!)说明:如果属性为true,我需要具有元素的类型.因此,如果属性为true,则XML输出可能为:
<Approval Approved="true">
<By>RT</By>
<Date>27/07/2011</Date>
</Approval>
Run Code Online (Sandbox Code Playgroud)
如果它未被批准,XML输出可能是
<Approval Approved="false" />
Run Code Online (Sandbox Code Playgroud)
是否可以在XSD中指定类似的内容?
我正在定义模式,但是在eclipse中验证它会产生以下错误.
src-resolve:无法将名称'common:Name'解析为(n)'type definition'组件.
我的架构如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.mycompany.com/myproject/service/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.mycompany.com/myproject/service/v1"
xmlns:product="http://www.mycompany.com/otherproject/service/products/v1"
xmlns:common="http://www.mycompany.com/myproject/service/common/v1" elementFormDefault="qualified">
<xsd:import namespace="http://www.mycompany.com/otherproject/service/products/v1" schemaLocation="products_v1.xsd" />
<xsd:import namespace="http://www.mycompany.com/myproject/service/common/v1" schemaLocation="common_v1.xsd" />
<xsd:element name="GetProductRequest" type="tns:GetProductRequest">
<xsd:annotation>
<xsd:documentation>Get Product Request</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="GetProuctRequest">
<xsd:annotation>
<xsd:documentation>Get Product Request</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="ID" type="common:ID" minOccurs="1" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>ID</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="Name" type="common:Name" minOccurs="1" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>Name</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
.....
Run Code Online (Sandbox Code Playgroud)
和common_v1.xsd看起来如下
<xsd:schema targetNamespace="http://www.mycompany.com/myproject/service/common/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.mycompany.com/myproject/service/common/v1"
elementFormDefault="qualified">
<xsd:complexType name="ID">
<xsd:annotation>
<xsd:documentation>ID</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="X" type="xsd:string" minOccurs="1" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>X</xsd:documentation>
</xsd:annotation> …Run Code Online (Sandbox Code Playgroud) 我相信这与keyref我有关,但我不确定,我真的不确定它是否可以完成.
例如,假设我有myElement1和myElement2.如果XML文件中没有myElement2,则myElement1必须存在,否则它是可选的.
有没有办法在我的XSD文件中强制进行这种类型的验证?
如果未指定最大长度,xsd字符串的默认最大长度是多少?
https://www.w3schools.com/xml/schema_facets.asp
maxLength - 指定允许的最大字符数或列表项.必须等于或大于零.
如果没有指定,它是零吗?
鉴于XSD如下:
<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:std="http://..." targetNamespace="...">
<xs:element name="SomeRootNode" type="std:SomeRootNodeType" />
...
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
它定义了一些允许来自不同命名空间的子进程的元素.
我想用自己的模式扩展这个模式,并在基础文档中插入子元素和特定元素的属性.例如,myElementX或myAttributeY必须具有父节点std:SomeRootNode.然后,组合文档应该能够允许任何第三方继续以基本模式已经允许的任何方式扩展文档,但是对于来自我的命名空间的元素和属性,我想验证所有元素和属性是否具有正确的父节点并仅出现在基本文档中允许的位置.
怎么能实现这一目标?
我希望有一个干净的解决方案,而不是重新定义我扩展的基础架构.如果发布新版本的基础架构,我希望能够轻松适应.每次发布新版本的基础文档时,我都不想用新的重新定义来改变我的(除非它对我的设计有重大改变).
我正在努力获取一个xml文件来验证XSD架构,我在验证时遇到问题.每当我确认我得到错误说
"架构有效性错误:元素'{http://services.website.com/ProgramResponse}Population':''不是原子类型'xs:double'的有效值."
我相信这个错误发生是因为我在该字段中有一个空字符,显示如下:
<HarvPop> </ HarvPop>
因此,为了解决这个问题,我尝试对元素使用nillable ="true"属性,这样它们就可以为null,但仍然显示为空.这似乎是唯一的解决方案,但它根本不起作用.我仍然得到错误.
我目前正在使用XMLMate进行验证,我再次对其进行了多次在线验证.错误仍然存在.任何建议都会很棒.
<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)
<xsd:element name="Reports" type="tns:ReportsType"/>
<xsd:complexType name="ReportsType">
<xsd:sequence>
<xsd:element name="Report" type="tns:ReportType" maxOccurs="unbounded" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ReportType">
<xsd:sequence>
<xsd:element name="Id" nillable="true"/>
<xsd:element name="Brand" type="xsd:string"/>
<xsd:element name="Address" type="xsd:string"/>
<xsd:element name="City" type="xsd:string"/>
<xsd:element name="State" type="xsd:string"/>
<xsd:element name="ZipCode" type="xsd:string"/>
<xsd:element name="Entry" type="tns:EntryType" maxOccurs="unbounded" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="EntryType">
<xsd:sequence>
<xsd:element name="RM" nillable="true" type="xsd:double"/>
<xsd:element name="Pop" nillable="true" type="xsd:double"/>
<xsd:element name="Wt" nillable="true" type="xsd:double"/>
<xsd:element name="EntryId" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
Run Code Online (Sandbox Code Playgroud)
<tag name="default" abc="10" def="20> <!-- not valid, abc and def should be mutually exclusive -->
<tag name="default1" abc="10"> <!-- valid -->
<tag name="default2" def="20> <!-- valid -->
Run Code Online (Sandbox Code Playgroud)
我能放进我的XSD,这样@abc并@def不能共存同一元素的属性?
如果它们在同一个元素上共存,那么验证会失败?