我正在寻找一个工具,它将采用XML实例文档并输出相应的XSD架构.
我当然认识到,与手工创建模式相比,生成的XSD模式将受到限制(它可能不会处理可选或重复元素或数据约束),但它至少可以作为一个快速起点.
我已经制作了一个XML Schema - 基本上都是代码 - 并且想知道代码是否可以生成这样的代码:

如果是这样我该怎么办?
我很难找到这个.如何在XML模式文件中为XML定义一个如下所示的元素:
<option value="test">sometext</option>
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何定义一个类型的元素,xs:string也有一个属性.
这是我到目前为止所得到的:
<xs:element name="option">
<xs:complexType>
<xs:attribute name="value" type="xs:string" />
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud) 我看到我们有多个url作为此属性的值,如spring:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
Run Code Online (Sandbox Code Playgroud)
为什么需要它以及它用于什么?Spring会进入网址并验证吗?xmlns和xsi:schemaLocation有什么区别?
我有一个巨大的QuickBooks SDK .XSD模式文件,它定义了我可以从QuickBooks发送/接收的XML请求/响应.
我希望能够从这些.XSD文件轻松生成Java类,然后我可以使用它来将XML编组为Java对象,将Java对象编组为XML.
是否有捷径可寻...?
理想情况下,在运行时不需要基本Java发行版外部的任何库.但我很灵活......
我已经开始创建XSD和几个例子为发现xs:integer和xs:int.
xs:integer和之间有什么区别xs:int?什么时候应该用xs:integer?什么时候应该用xs:int?
有人可以解释如何使用Notepad ++来针对xsd验证xml文件."XML工具"插件下拉列表中没有提供指定XSD文件的选项.XML插件在plugins子目录中正确安装,3个DLL被复制到Notepad ++ EXE子目录.其他XML"验证"功能可以工作,但无法验证XSD.
我正在尝试创建一个XSD,并尝试使用以下要求编写定义:
我环顾四周,发现像各种解决方案这样:
<xs:element name="foo">
<xsl:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="child1" type="xs:int"/>
<xs:element name="child2" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
但据我所知xs:choice仍然只允许单个元素选择.因此,将MaxOccurs设置为无界限应该只意味着子元素中的"任何一个"可以多次出现.这准确吗?
如果上述解决方案不正确,我怎样才能实现我在上述要求中所说的内容?
编辑:如果要求如下,该怎么办?
例如,此xml有效:
<foo>
<child1> value </child1>
<child1> value </child1>
<child3> value </child3>
<child2> value </child2>
<child4> value </child4>
<child1> value </child1>
</foo>
Run Code Online (Sandbox Code Playgroud)
但这不是(缺少孩子3)
<foo>
<child1> value </child1>
<child1> value </child1>
<child2> value </child2>
<child4> value </child4>
<child1> value </child1>
</foo>
Run Code Online (Sandbox Code Playgroud) 我使用的是Spring,application-context.xml我有以下定义:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.xsd"
>
Run Code Online (Sandbox Code Playgroud)
.....
当我的互联网连接丢失时,我无法通过tomcat或jetty运行我的应用程序.
它给:
[main] WARN org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document '/spring-beans-2.0.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:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:96)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:380)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318) …Run Code Online (Sandbox Code Playgroud)