标签: xsd

如何在XSD中指定有序列表

我有一个需要订购的数字列表.目前它们在XML中是这样的:

<value_1>0.2</value_1>
<value_2>0.4</value_2>
<value_3>0.6</value_3>
...
<value_N>1.8</value_N>
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来做到这一点,它可以在XSD中很好地定义,并且数据是以指定的顺序从解析器返回的?

编辑 XSD片段:

<xs:complexType>
    <xs:sequence>
        <xs:element name="value_1" type="xs:decimal"/>
        <xs:element name="value_2" type="xs:decimal"/>
        <xs:element name="value_3" type="xs:decimal"/>
        ...
        <xs:element name="value_N" type="xs:decimal"/>
    </xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

xml xsd

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

来自xsd的maven-jaxb2-plugin类生成(版本错误)

我的pom.xml,

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.rajkishan</groupId>
<artifactId>RESTful-Swagger</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>

<name>RESTful-Swagger</name>

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.2.4.RELEASE</version>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <start-class>com.rajkishan.Application</start-class>
</properties>

 <dependencies>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>com.mangofactory</groupId>
    <artifactId>swagger-springmvc</artifactId>
    <version>1.0.2</version>
</dependency>

</dependencies>

 <build>
<plugins>

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>

    <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.12.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaDirectory>src/main/resources</schemaDirectory>
                <schemaIncludes>
                    <include>Greeting.xsd</include>
                </schemaIncludes>
                <generatePackage>com.rajkishan.xmlgen</generatePackage>
            </configuration>
        </plugin>

</plugins>
Run Code Online (Sandbox Code Playgroud)

当我在"Netbeans"中使用maven构建时,这很好用.

但是,如果我在Eclipse Luna中使用它,它会给出错误;

目标org.jvnet.jaxb2.maven2的执行默认值:maven-jaxb2-plugin:0.12.3:生成失败:执行org.jvnet.jaxb2.maven2时缺少必需的类:maven-jaxb2-plugin:0.12.3: generate:com/sun/xml/bind/api/ErrorListener

但是,如果我将版本更改为0.12.1,如下所示,它可以工作;

<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java xml xsd maven

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

xsd.cs文件是如何使用的?

在biztalk项目中,为什么有些XSD文件有隐藏的xsd.cs而有些则没有?这些文件用于什么以及为什么,修改XSD和重建不会修改.cs文件?

例如:我有一个XSD,用于将消息映射到SQL发送/接收端口并执行存储过程.如果我更改存储过程(例如更改,删除,添加参数),从而更改xsd以匹配,则在部署业务流程时不会反映这些更改,除非我删除xsd.cs. 我可以在BizTalk管理控制台的Schemas选项卡中看到修改后的xsd.我可以看到它已被修改,但我仍然会收到消息路由/映射错误,除非删除了.cs并重新部署了业务流程.顺便说一句,删除后,它似乎永远不会再生,虽然它也不会导致任何问题.

xsd biztalk biztalk-2013

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

vb.net - 从XSD创建类并生成xml

我有一个xsd文件,需要从中创建一个xml.某些页面假定使用Visual Studio中的xsd.exe.但是如何将生成的类链接到xsd,从中创建xml文件?

或者是否有另一种方法可以通过xsd架构将值导出到xml文件?

xml vb.net xsd

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

有没有办法在没有实际解析的情况下找到XML文件中的异常?

我有一个应用程序,只需将XML文件作为BLOB上传到数据库.我知道有几种方法可以使用XML验证DocumentBuilderFactory,DocumentBuilder然后解析它等,但我所说的数据很大,输入XML文件中出现异常的可能性较小.

但是,只是为了确保语法正确,有没有办法捕获文件中的异常而不实际解析每个文件?

xml parsing xsd xml-validation xsd-validation

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

为什么xs:choice在生成的xml中允许多个不同的xs:元素?

我知道这个相关问题,我理解我的问题与答案相矛盾,但以下XML文件完全符合以下XMLSchema

我的XML数据:

<?xml version="1.0" encoding="utf-8"?>
<myElements>
    <el1>bla</el1>
    <el1>bla</el1>
    <el1>blabla</el1>
    <el2>bgt</el2>
    <el2>pel</el2>
    <el3>sdf</el3>
</myElements>
Run Code Online (Sandbox Code Playgroud)

我的XMLSchema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="myElements">
        <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="el1" />
                <xs:element name="el2" />
                <xs:element name="el3" />
                <xs:element name="el4" />
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

W3学校和其他消息来源说:

XML Schema choice元素只允许声明中包含的一个元素出现在contains元素中.

在我看来,这意味着我的XML数据应该只接受其中一个:

  • 0到任何el1
  • 0到任何el2
  • 0到任何el3
  • 0到任何el4

但是,如果您尝试将我的xml数据验证到我的xmlschema,它是有效的,我不明白为什么.

我是否完全误解了文档?

我使用的验证器是否松散且非标准?如果是的话,什么是一个好的验证器,为什么有人会在我描述的情况下使用选择?(是的,我确实遇到过这个)

xml xsd xsd-validation

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

根据模式验证XML-找不到元素的声明

我对XML验证非常陌生,因此很抱歉基本问题。我有以下文件:

<tincan xmlns="http://projecttincan.com/tincan.xsd">
  <activities>
    <activity id="TestActivity" type="course">
      <name lang="und">MyCourse</name>
      <description lang="und"/>
      <launch lang="und">start.html</launch>
    </activity>
    <activity id="p001" type="objective">
      <name lang="und">First Page</name>
      <description lang="und">First Page</description>
    </activity>
  </activities>
</tincan>
Run Code Online (Sandbox Code Playgroud)

我正在尝试根据以下架构对其进行验证:http : //projecttincan.com/tincan.xsd(我还尝试从XML中删除该架构并从外部提供该架构)。

我总是收到以下异常: cvc-elt.1: Cannot find the declaration of element 'tincan'

通过查看模式,我看到该tincan元素已在其中定义,并且也存在于我的XML中,因此我无法理解此异常的根源。如果有人可以解释验证的工作原理,我将感到非常高兴。

编辑:我的验证代码:

DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(stream);

// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(getClass().getClassLoader().getResource("tincan.xsd").getFile()); …
Run Code Online (Sandbox Code Playgroud)

java xml validation xsd

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

封送JSON时,Jackson忽略XmlElement名称/大小写

我正在尝试从XSD-> POJO-> JSON转到要区分大小写的UPS跟踪API。我在生成的JSON中使用Jackson 2.6.7。当我在下面看到时,我看到了骆驼箱的名称:

"TrackRequest": { "InquiryNumber": "1Z12345E6205277936" }

生成的Java bean的注释如下:

@XmlElement(name = "TrackRequest")
protected TrackRequest trackRequest;
Run Code Online (Sandbox Code Playgroud)

我尝试了一些映射功能设置,例如USE_WRAPPER_NAME_AS_PROPERTY_NAME和USE_STD_BEAN_NAMING,它们似乎并没有达到预期的效果。

我正在生成JSON,如下所示:

ObjectMapper mapper = new ObjectMapper();
String jsonRequest = mapper.writeValueAsString(upsRequest);
Run Code Online (Sandbox Code Playgroud)

upsRequest bean看起来像这样:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "upsSecurity",
    "trackRequest"
})
@XmlRootElement(name = "Request")
public class Request {

    @XmlElement(name = "UPSSecurity")
    protected UPSSecurity upsSecurity;
    @XmlElement(name = "TrackRequest")
    protected TrackRequest trackRequest;

    /**
     * Gets the value of the upsSecurity property.
     * 
     * @return
     *     possible object is
     *     {@link UPSSecurity }
     * …
Run Code Online (Sandbox Code Playgroud)

java json xsd jersey jackson

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

意外元素(uri:"",local:"").预期要素是(无)

我无法使用cxf-xjc-plugin将响应xml映射到xsd生成的java.

的pom.xml

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-xjc-plugin</artifactId>
                <version>2.3.0</version>
                <configuration>
                    <extensions>
                        <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0</extension>
                    </extensions>
                </configuration>
                <executions>
                    <execution>
                        <id>generate-sources-trans</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xsdtojava</goal>
                        </goals>
                        <configuration>
                            <sourceRoot>${basedir}/src/main/java</sourceRoot>
                            <xsdOptions>
                                <xsdOption>
                                    <xsd>src/main/resources/Response.xsd</xsd>
                                    <packagename>com.test.response</packagename>
                                    <extensionArgs>
                                        <extensionArg>-Xdv</extensionArg>
                                    </extensionArgs>
                                </xsdOption>                                
                                </xsdOption>
                            </xsdOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
Run Code Online (Sandbox Code Playgroud)

Response.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="urn:automatedIDgenerationResponse" xmlns:tns="urn:automatedIDgenerationResponse" xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!-- definition of simple elements -->
    <complexType name="generatedIDs">
            <sequence>
                <element name="idType" type="string"/>
                <element name="id" type="string"/>
            </sequence>
    </complexType>
    <element name="automatedIDgenerationResponse" type="tns:automatedIDResponse"/>
    <complexType name="automatedIDResponse">
        <sequence>
            <element name="requestID" type="string" nillable="false"/>
            <element name="status" type="string" nillable="false"/>
            <element name="errorCode" …
Run Code Online (Sandbox Code Playgroud)

java xml xsd pom.xml cxf-xjc-plugin

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

致命错误:1:1:prolog中不允许内容.org.xml.sax.SAXParseException

我试图用Java读取XML文件,然后将其与XML Schema进行比较,但我无法通过此错误:

[致命错误]:1:1:prolog中不允许内容.org.xml.sax.SAXParseException; lineNumber:1; columnNumber:1; 序言中不能有内容.

这是文件读取的开始

try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();          
        Document doc = dBuilder.parse(new InputSource(new StringReader("myfile.xml"))); // ERROR OCCURS HERE
Run Code Online (Sandbox Code Playgroud)

我通过HEX编辑器扫描了我的XML,但我没有在里面找到任何奇怪的字符,所以我不知道问题出在哪里

将myfile.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<Schedule xmlns ="schedule"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="schedule.xsd">
    <Lesson>
        <Title>Artificial Intelligence</Title>
        <Lecture Classroom="BA">
            <Day>Wednesday</Day>
            <Time>09-11</Time>
        </Lecture>
        <Professor>Hatzilygeroudis</Professor>
    </Lesson>
    <Lesson>
        <Title>Constraint Satisfaction Problems</Title>
        <Lecture Classroom="B3">
            <Day>Monday</Day>
            <Time>19-21</Time>
        </Lecture>
    </Lesson>
    <Lesson>
        <Title>Knowledge Representation in Web</Title>
        <Lecture Classroom="P200">
            <Day>Friday</Day>
            <Time>15-17</Time>
        </Lecture>
        <Professor>Hatzilygeroudis</Professor>
    </Lesson>
    <Lesson>
        <Title>Artificial Intelligence</Title>
        <Lecture>
            <Day>Monday</Day>
            <Time>19-21</Time>
        </Lecture>
    </Lesson>
    <Lesson>
        <Title>AI …
Run Code Online (Sandbox Code Playgroud)

java xml xsd xml-parsing

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