标签: xsd

发布xml架构的标准方法

假设我有一个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"

我的问题是:

  1. 这是xml标准的一部分吗?每个xml解析器是否"知道"如何从命名空间URI中查找架构?
  2. 是否有一个独立的"xsd repo"工具,可以帮助我在我的域下发布xsds,而无需自己设置Web服务器的麻烦.我正在想象某种RESTful API,它允许我使用他们的命名空间来创建PUT新的模式,DELETE现有的模式,当然还有GET新的模式URI

xml xsd namespaces

2
推荐指数
1
解决办法
819
查看次数

在java中以编程方式生成XSD

是否有任何API可以在java中以编程方式生成XSD.我需要从Json-Schema生成XSD,我将阅读Json Schema并基于我在解析期间遇到的元素需要创建适当的XSD元素.因此,如果有任何可以使用XSD元素的API,它将有助于我在开发过程中.

java schema parsing xsd jsonschema

2
推荐指数
1
解决办法
3428
查看次数

无法读取架构文档'http://www.springframework.org/schema/tool/spring-tool-4.1.xsd'

加载我的应用程序弹簧上下文时,我收到以下错误(仅在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)

java xml spring xsd

2
推荐指数
1
解决办法
8557
查看次数

XSD中不区分大小写的正则表达式

有没有更好的方法来做到以下几点?

<xs:restriction base="xs:string">
    <xs:pattern value="hulu|Hulu|netflix|Netflix"></xs:pattern>
</xs:restriction>
Run Code Online (Sandbox Code Playgroud)

基本上我想要一个不区分大小写的匹配.

regex xsd

2
推荐指数
1
解决办法
1687
查看次数

XSD重用complexType元素

我正在使用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)

xml xsd jdeveloper

2
推荐指数
1
解决办法
838
查看次数

Gradle构建失败

我正在使用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)

java spring xsd jaxb gradle

2
推荐指数
2
解决办法
3414
查看次数

如何在XSD中使用xsi:type限制XML元素的值?

我想基于属性值验证元素的文本值.例如

<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是复杂得多用很多ObjectParameter节点,这是我的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)

xml xsd

2
推荐指数
1
解决办法
4326
查看次数

为什么XSD规范接受时区有-14H?

我在xquery中玩了一些dateTime函数,我注意到xquery接受时区有-14小时的日期.

查看维基百科链接,我可以看到最小允许时区是-12H,但xpath函数似乎允许-14H.我错过了什么吗?

xml timezone xpath xsd xquery

2
推荐指数
1
解决办法
95
查看次数

Xquery从XSD架构获取属性名称和类型?

我正在关注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)

xml xsd xquery marklogic marklogic-8

2
推荐指数
1
解决办法
876
查看次数

如何使用lxml验证多个xsd架构?

我正在编写一个单元测试,通过获取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)

python xml xsd lxml

2
推荐指数
1
解决办法
1194
查看次数