假设我有一个xml
模式,定义命名空间:http://foo.com/mySchema
.是否有标准方法来发布模式,以便模式的xml实例只需要定义命名空间而不是xsi:schemaLocation
?
例如,如果你看一下imdb的sitemap xml:http://www.imdb.com/sitemap_US_index.xml.gz
xml定义了一个名称空间:http://www.sitemaps.org/schemas/sitemap/0.9,但没有定义schemaLocation.
如果你访问这个URI,那里有2个xsds:"siteindex.xsd"和"sitemap.xsd"
我的问题是:
PUT
新的模式,DELETE
现有的模式,当然还有GET
新的模式URI
是否有任何API可以在java中以编程方式生成XSD.我需要从Json-Schema生成XSD,我将阅读Json Schema并基于我在解析期间遇到的元素需要创建适当的XSD元素.因此,如果有任何可以使用XSD元素的API,它将有助于我在开发过程中.
加载我的应用程序弹簧上下文时,我收到以下错误(仅在Linux机器上,在Windows上似乎以某种方式工作):
无法读取架构文档" http://www.springframework.org/schema/tool/spring-tool-4.1.xsd ",因为1)找不到该文档; 2)文件无法阅读; 3)文档的根元素不是xsd:schema.
Stacktrace如下:
org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/spring/score/context/scoreRepositoryContext.xml]
2015-03-30 11:07:49:336 127901 [main] WARN org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Ignored XML validation warning
org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/tx/spring-tx.xsd; lineNumber: 12; columnNumber: 150; schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tool/spring-tool-4.1.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not xsd:schema.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:99)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:433)
at
...
at org.springframework.shell.Bootstrap.main(Bootstrap.java:58)
Caused …
Run Code Online (Sandbox Code Playgroud) 有没有更好的方法来做到以下几点?
<xs:restriction base="xs:string">
<xs:pattern value="hulu|Hulu|netflix|Netflix"></xs:pattern>
</xs:restriction>
Run Code Online (Sandbox Code Playgroud)
基本上我想要一个不区分大小写的匹配.
我正在使用Jdeveloper 12c.我正在尝试使用a complexType
作为引用在另一个元素中键入另一个元素complexType
.Jdev告诉我它无法找到AddressInfo
参考.以下是相关代码的片段,请帮忙:
<?xml version="1.0" encoding="UTF-8"?>
<schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://xmlns.oracle.com/SquareEdge/SEPPO/ProcessPO"
xmlns="http://www.w3.org/2001/XMLSchema">
<complexType name="AddressInfo">
<sequence>
<element type="string" name="FirstName"/>
<element type="string" name="LastName"/>
<element type="string" name="Street"/>
<element type="string" name="City"/>
<element type="string" name="State"/>
<element type="short" name="ZipCode"/>
<element type="unsignedLong" name="PhoneNumber"/>
</sequence>
</complexType>
<complexType name="Billing">
<sequence>
<element name="PaymentCardName" type="string" maxOccurs="1"/>
<element name="PaymentCardNumber" type="unsignedLong"maxOccurs="1"/>
<element name="ExpirationDate" type="unsignedShort" maxOccurs="1"/>
<element name="BillingAddress" maxOccurs="1" type="AddressInfo"/>
</sequence>
</complexType>
Run Code Online (Sandbox Code Playgroud) 我正在使用https://spring.io/guides/gs/producing-web-service/#initial上的教程来尝试生成SOAP Web服务.我正在使用Gradle来管理我的依赖项.
我有一个.xsd文件,它指定了我想要gradle创建的某些类.
但是,当我尝试在eclipse中的build.gradle文件上运行gradle构建时,我收到以下错误:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\zekucukkose\workspace2\gs-producing-web-service-initial\build.gradle'
line: 32
* What went wrong:
A problem occurred evaluating root project 'gs-producing-web-service-initial'.
> Could not find method jaxb() for arguments [com.sun.xml.bind:jaxb-xjc:2.2.4-1]
on root project 'gs-producing-web-service-initial'.
Run Code Online (Sandbox Code Playgroud)
第27至34行如下:
27 dependencies {
28 compile("org.springframework.boot:spring-boot-starter-web")
29 compile("org.springframework.boot:spring-boot-starter-ws")
30 testCompile("org.springframework.boot:spring-boot-starter-test")
31 compile("wsdl4j:wsdl4j:1.6.1")
32 jaxb("com.sun.xml.bind:jaxb-xjc:2.2.4-1")
33 compile(files(genJaxb.classesDir).builtBy(genJaxb))
34 }
Run Code Online (Sandbox Code Playgroud)
就我所知,jaxb是用于生成实际类的东西.
如果有人可以提供帮助,我真的很感激.谢谢
这是整个脚本:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE")
}
}
apply plugin: 'java'
apply plugin: …
Run Code Online (Sandbox Code Playgroud) 我想基于属性值验证元素的文本值.例如
<Device xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Parameter xsi:type="xsd:unsignedInt">-100</Parameter>
<Parameter xsi:type="xsd:boolean"></Parameter>
<Parameter>hello</Parameter>
</Device>
Run Code Online (Sandbox Code Playgroud)
以上都应该失败.对于布尔值,除"true"或"false"(甚至空字符串)外,不应接受任何内容
我的XML是复杂得多用很多Object
和Parameter
节点,这是我的xsd这是递归地验证所有的节点
<xs:complexType name="deviceType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Object"/>
<xs:element ref="Parameter"/>
</xs:choice>
</xs:complexType>
<xs:complexType name="objType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Object"/>
<xs:element ref="Parameter"/>
</xs:choice>
<!-- Add all valid attributes for 'Object' type here -->
<xs:attribute name="Id" use="required"/>
<xs:attribute name="Flag" use="required"/>
<xs:anyAttribute processContents="lax"/>
</xs:complexType>
<xs:complexType name="paramType" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Object"/>
<xs:element ref="Parameter"/>
</xs:choice>
<xs:attribute name="Id" use="required"/>
<xs:attribute name="Flag" use="required"/>
<xs:anyAttribute processContents="lax"/>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
但是我面临这个错误.
Type 'xsd:unsignedInt' is …
Run Code Online (Sandbox Code Playgroud) 我在xquery中玩了一些dateTime函数,我注意到xquery接受时区有-14小时的日期.
我正在关注marklogic的教程,
https://developer.marklogic.com/learn/2007-04-schema
在一个场景中,我有xsd文件
<!-- tutorial.xsd -->
<xs:schema targetNamespace="http://marklogic.com/tutorial"
attributeFormDefault="unqualified"
elementFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="name" type="xs:token"
abstract="false" nillable="false"/>
<xs:element name="qualification" type="xs:token"
abstract="false" nillable="false"/>
<xs:element name="born" type="xs:date"
abstract="false" nillable="false"/>
<xs:element name="dead" type="xs:date"
abstract="false" nillable="false"/>
<xs:element name="isbn" type="xs:unsignedLong"
abstract="false" nillable="false"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="available" type="xs:boolean"/>
<xs:attribute name="lang" type="xs:language"/>
<xs:element name="title" abstract="false" nillable="false">
<xs:complexType mixed="false">
<xs:simpleContent>
<xs:extension base="xs:token">
<xs:attribute ref="lang" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="library" abstract="false" nillable="false">
<xs:complexType mixed="false">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="book" maxOccurs="unbounded" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="author" abstract="false" …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个单元测试,通过获取xsd模式并使用python的lxml库验证来验证我生成的sitemap xml:
这是我的根元素的一些元数据:
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
http://www.google.com/schemas/sitemap-image/1.1
http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd"
Run Code Online (Sandbox Code Playgroud)
而这个测试代码:
_xsd_validators = {}
def get_xsd_validator(url):
if url not in _xsd_validators:
_xsd_validators[url] = etree.XMLSchema(etree.parse(StringIO(requests.get(url).content)))
return _xsd_validators[url]
# this util function is later on in a TestCase
def validate_xml(self, content):
content.seek(0)
doc = etree.parse(content)
schema_loc = doc.getroot().attrib.get('{http://www.w3.org/2001/XMLSchema-instance}schemaLocation').split(' ')
# lxml doesn't like multiple namespaces
for i, loc in enumerate(schema_loc):
if i % 2 == 1:
get_xsd_validator(schema_loc[i]).assertValid(doc)
return doc
Run Code Online (Sandbox Code Playgroud)
验证失败的示例XML:
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
http://www.google.com/schemas/sitemap-image/1.1
http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd"
> …
Run Code Online (Sandbox Code Playgroud) xsd ×10
xml ×7
java ×3
spring ×2
xquery ×2
gradle ×1
jaxb ×1
jdeveloper ×1
jsonschema ×1
lxml ×1
marklogic ×1
marklogic-8 ×1
namespaces ×1
parsing ×1
python ×1
regex ×1
schema ×1
timezone ×1
xpath ×1