我正在编写有关编写自定义spring命名空间处理程序的教程:http: //static.springsource.org/spring/docs/2.5.x/reference/extensible-xml.html
一切都工作得很好,直到我到B.5节注册新的处理程序和模式.
我尝试将spring.handlers和spring.schemas放入我的项目中 - 没有用
我能够找到文件| 设置| Schema和DTD,它确实在编辑器中启用了自动完成,但处理程序仍未注册.这也没有转换为spring.schemas文件中的条目.
简而言之,有人可以解释如何在intelliJ 11.1.2中执行以下操作吗?
a)配置它以识别新的模式和命名空间处理程序b)在构建工件时将正确的信息放入META-INF/spring.handlers和spring.schemas文件中?
任何帮助将不胜感激.
我正在尝试在另一个环境中模拟现有的Web服务以进行测试,并遇到了障碍.
我正在尝试在WCF中创建这个Mock服务
我正在嘲笑的服务(在WCF中没有开发)有一个具有这种类型定义的实体:
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="dog" nillable="true" type="xs:string"/>
</xs:sequence>
Run Code Online (Sandbox Code Playgroud)
注意maxOccurs ="unbounded"消息本身看起来像这样:
<dog>1</dog>
<dog>2</dog>
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何定义我的DataContract来处理这个问题.我假设只使用如下数组类型:
[DataContract]
public class P56040Input
{
[DataMember]
public string[] dog { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
会对应,但它会对新类型(arrayofstring)做出意想不到的事情:
<xs:sequence>
<xs:element xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" minOccurs="0" name="dog" nillable="true" type="q1:ArrayOfstring"/>
</xs:sequence>
Run Code Online (Sandbox Code Playgroud)
这甚至可以在WCF中进行模拟吗?
我正在尝试使用从xml文件绑定数据到从模式文件xsd生成但是给出null的类来创建对象.
这是我的xsd,我从中生成了我的java类:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="people">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="employee"/>
<xsd:element ref="customer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="employee">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref='name'/>
<xsd:element ref='country'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name='name'>
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace='http://www.w3.org/namespace/'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name='country'>
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace='http://www.w3.org/namespace/'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="customer">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref='cname'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name='cname'>
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace='http://www.w3.org/namespace/'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
我的XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<people>
<employee>
<name>John</name>
<country>India</country>
</employee>
<customer>
<cname>steve</cname>
</customer>
</people>
Run Code Online (Sandbox Code Playgroud)
这里我的代码试图将xml数据绑定到java对象,但是给出了null:
File file = …
Run Code Online (Sandbox Code Playgroud) 我正在一个maven项目工作.Atm我只有实体,映射和配置文件.我试图用junit测试我的hibernate映射.
我找不到问题.我可以验证netbeans中的xml文件,但是当我运行我的测试时,我收到以下错误.
netbeans中的验证:
XML validation started.
Checking file:/C:/Users/Err/Documents/NetBeansProjects/PinkSocks/src/main/resources/hibernate.cfg.xml...
Referenced entity at "http://localhost:8080/files/hibernate-configuration-4.0.xsd".
XML validation finished.
Run Code Online (Sandbox Code Playgroud)
错误:
Initial SessionFactory creation failed.org.hibernate.MappingException: invalid configuration
at bleh.mihihi.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:25)
at bleh.mihihi.utils.HibernateUtil.<clinit>(HibernateUtil.java:16)
at bleh.mihihi.utils.HibernateUtilTest.setUp(HibernateUtilTest.java:20)
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2014)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1931)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1910)
at bleh.mihihi.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:21)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 25; Document is invalid: no grammar found.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
Run Code Online (Sandbox Code Playgroud)
hibernate.cfg.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration http://localhost:8080/files/hibernate-configuration-4.0.xsd">
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/pinksocks</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property> …
Run Code Online (Sandbox Code Playgroud) 我们项目的要求之一如下:
我们只从客户端WSDL和XSD文件获得.我们的任务是基于这些WSDL和XSD文件生成SOAP消息并提取SOAP主体.
我们应该采取的第一步是从给定的WSDL和XSD文件生成客户端代理文件.主WSDL文件有多个导入,导入的XSD文件也有一些导入.我试图通过使用SvcUtil.exe实用程序来完成客户端代理文件生成,但错误出现了.
我用这种方式运行SvcUtil.exe:
E:\ Projekti\WCF\XSD> svcutil/noconfig rosrazna.ru.xsd.SmevUnifoService.wsdl roskazna.ru.xsd.ResponseTemplate.xsd roskazna.ru.xsd.PGU_ImportRequest.xsd roskazna.ru.xsd.PGU_DataRequest.xsd roskazna. ru.xsd.PGU_ChargesResponse.xsd roskazna.ru.xsd.ExportPaymentsResponse.xsd roskazna.ru.xsd.ExportIncomesResponse.xsd roskazna.ru.xsd.ExportQuittanceResponse.xsd roskazna.ru.xsd.Ticket.xsd
但是,出现了这个错误:
Microsoft(R)服务模型元数据工具[Microsoft(R)Windows(R)Communication Foundation,版本3.0.4506.2152]版权所有(c)Microsoft Corporation.版权所有.
生成文件...警告:未生成任何代码.如果您尝试生成客户端,这可能是因为元数据文档不包含任何有效的合同或服务,或者因为发现所有合同/服务都存在于/ reference assemblies中.验证是否已将所有元数据文档传递给该工具.
警告:如果要从模式生成数据协定,请确保使用/ dataContractOnly选项.
我不得不提到我没有在SvcUtil.exe命令中从主WSDL文件中导入的XSD文件中导入.我不知道怎么把它们.
那么,如何解决这个问题呢?
先感谢您.
戈兰
在使用Java的XML Validator
(我相信使用Apache Xerces实现)时,我遇到了一些非常奇怪的行为.
我正在尝试针对XSD验证一些XML文档,并且我想记录导致文档无效的任何内容.我认为实施我自己ErrorHandler
会允许我这样做.我很快发现这导致XML文档被错误地验证(即无效的XML被识别为对我的XSD有效).
我做了一些测试,发现简单地将Validator
's 设置ErrorHandler
为任何东西都会导致这种行为,如下所示.
validator.validate(invalidXmlSource); // XML correctly identified as INVALID
validator.setErrorHandler(new DefaultHandler());
validator.validate(invalidXmlSource); // XML incorrectly identified as VALID
Run Code Online (Sandbox Code Playgroud)
我会假设当没有指定一个时Validator
使用DefaultHandler
,所以我不明白为什么行为正在改变.
这里发生了什么?
编辑
public void validate(File dir, String xsdPath) {
File schemaFile = new File(xsdPath);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
//validator.setErrorHandler(new DefaultHandler()); <-- this line causes incorrect validation
for (File xmlFile: dir.listFiles()) {
try {
validator.validate(new StreamSource(xmlFile));
System.out.println("File '" + …
Run Code Online (Sandbox Code Playgroud) 我从客户那里得到了以下XSD位.它是传统架构的一部分,涵盖了数十个文件.
<xs:element name="stateProvinceName">
<xs:complexType mixed="true">
<xs:attributeGroup ref="xml:attlist.global-attributes"/>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
我想弄清楚他们真正想要的是什么.没有子元素,那么'xs:mixed'的含义是什么?它应该是简单的内容,还是没有内容?
我告诉他们应该使用更多的标准结构,例如
<xs:element name="stateProvinceName">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="xml:attlist.global-attributes"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
但他们不确定这意味着什么.两种模式都接受
<stateProvinceName ID="345643">California</stateProvinceName>
Run Code Online (Sandbox Code Playgroud)
和
<stateProvinceName ID="345643"/>
Run Code Online (Sandbox Code Playgroud) 我有一个问题,空值在一台服务器上验证失败,但它适用于我所有其他服务器.问题发生在较新的PHP版本(5.3.8)上,适用于较旧的版本(5.2.4).
以下是一些失败的孤立元素:
XML输入:
<clbburnfuelbias></clbburnfuelbias>
<clbburntimebias></clbburntimebias>
Run Code Online (Sandbox Code Playgroud)
XSD验证:
<xs:element name="clbburnfuelbias" type="data-fuelbias"/>
<xs:element name="clbburntimebias" type="data-timebias"/>
<xs:simpleType name="data-fuelbias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="data-timebias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-59"/>
<xs:maxInclusive value="59"/>
</xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
错误:
错误1824:元素'clbburnfuelbias':该值不是原子类型'data-fuelbias'的有效值.错误1824:元素'clbburntimebias':该值不是原子类型
'data-timebias'的有效值.
在运行5.2.4的不同服务器上使用完全相同的输入和XSD文件我没有错误,xml有效.
我已经尝试将minOccurs ="0"添加到元素中,我已经尝试指定nullable ="true",但仍然会得到错误.
看来我的服务器上使用PHP 5.2.4忽略了空值,并使用5.3.8拒绝了.我使用过的建议是使用两个定义的并集,一个用于整数类型,另一个用于null值:
XSD:
<xs:element name="clbburnfuelbias" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="data-fuelbias null-string"/>
</xs:simpleType>
</xs:element>
<xs:simpleType name="data-fuelbias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="null-string">
<xs:restriction base="xs:string">
<xs:length value="0"/>
</xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用正则表达式来阅读我的文档以识别货币类型,无论它们是$
,£
还是a €
.我创建的正则表达式似乎不起作用,有人请告诉我它应该是什么.我真的很感激帮助:
我创建的正则表达式("\$|£|€]")
是在我的XSD文件中的simpleType中,用于验证文档.代码显示在冒号后面:
<xs:simpleType name="currencyType">
<xs:restriction base="utf8-string">
<xs:length value="1" />
<xs:pattern value="[\$|£|€]"/>
</xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud) 是否有GUI工具可以显示有关WSDL文件和XSD文件的详细信息?
也许WSDL编辑器也是一种选择.我的需求主要是检查我必须调用服务的结构和选项.最好是比仅仅读取XML文件本身更具图形性.
我尝试过Eclipse WSDL编辑器,它非常有用,但是我遇到了麻烦.那么,是否有类似的替代方案?(否则我需要修复Eclipse工具......)