我尝试使用Groovy在SoapUI中运行以下xsd验证
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.*
// setup validator
Validator validator;
def url = "file:///D:/SoapUI/XSDFile.xsd"
log.info url
URI uri = new URI(url);
InputStream inp = uri.toURL().openStream();
try
{
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
StreamSource entitySs = new StreamSource(inp);
Schema schema = factory.newSchema(entitySs);
assert(schema != null);
validator = schema.newValidator();
}
finally
{
inp.close();
inp = null;
}
def response = context.expand( "file:///D:/SoapUI/response.xml" )
log.info response
validator.validate(new StreamSource(new StringReader(response)))
但是我在SoapUI测试案例
的groovy步骤中遇到了错误:ERROR:org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.jaxp.validation.StreamValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source)
at javax.xml.validation.Validator.validate(Unknown Source)
at javax.xml.validation.Validator$validate.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Script1.run(Script1.groovy:33)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:149)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:239)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:48)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:148)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:43)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:135)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
根据网络上给出的解决方案我删除了不需要的字符,虽然我无法通过将文件从UTF8文件转换为ANSI
来查看但仍然给出同样的错误
这会引起其他问题吗?
响应
<GeocodeResponse>
<status>OK</status>
<result>
<type>locality</type>
<type>political</type>
<formatted_address>Rio de Janeiro, Brazil</formatted_address>
<address_component>
<long_name>Rio de Janeiro</long_name>
<short_name>Rio de Janeiro</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Rio de Janeiro</long_name>
<short_name>RJ</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Brazil</long_name>
<short_name>BR</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>-22.9035393</lat>
<lng>-43.2095869</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>-23.0830199</lat>
<lng>-43.7954493</lng>
</southwest>
<northeast>
<lat>-22.7490450</lat>
<lng>-43.0993817</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>-23.0830199</lat>
<lng>-43.7954493</lng>
</southwest>
<northeast>
<lat>-22.7490450</lat>
<lng>-43.0993817</lng>
</northeast>
</bounds>
</geometry>
</result>
</GeocodeResponse>
架构文件
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://maps.googleapis.com" elementFormDefault="qualified" xmlns="http://maps.googleapis.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="GeocodeResponse" type="_GeocodeResponse"/>
<xs:complexType name="result_geometry">
<xs:sequence>
<xs:element name="location" type="geometry_location"/>
<xs:element name="location_type" type="xs:string"/>
<xs:element name="viewport" type="geometry_viewport"/>
<xs:element name="bounds" type="geometry_bounds"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="viewport_southwest">
<xs:sequence>
<xs:element name="lathjj" type="xs:decimal"/>
<xs:element name="lng" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="bounds_northeast">
<xs:sequence>
<xs:element name="lat" type="xs:decimal"/>
<xs:element name="lng" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="geometry_viewport">
<xs:sequence>
<xs:element name="southwest" type="viewport_southwest"/>
<xs:element name="northeast" type="viewport_northeast"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="geometry_bounds">
<xs:sequence>
<xs:element name="southwest" type="bounds_southwest"/>
<xs:element name="northeast" type="bounds_northeast"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="bounds_southwest">
<xs:sequence>
<xs:element name="lat" type="xs:decimal"/>
<xs:element name="lng" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="viewport_northeast">
<xs:sequence>
<xs:element name="lat" type="xs:decimal"/>
<xs:element name="lng" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="_GeocodeResponse">
<xs:sequence>
<xs:element name="status" type="xs:string"/>
<xs:element name="result" type="GeocodeResponse_result"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="address_component">
<xs:sequence>
<xs:element name="long_name" type="xs:string"/>
<xs:element name="short_name" type="xs:string"/>
<xs:element name="type" type="xs:string" maxOccurs="2"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="GeocodeResponse_result">
<xs:sequence>
<xs:element name="type" type="xs:string" maxOccurs="2"/>
<xs:element name="formatted_address" type="xs:string"/>
<xs:element name="address_component" type="address_component" maxOccurs="3"/>
<xs:element name="geometry" type="result_geometry"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="geometry_location">
<xs:sequence>
<xs:element name="lat" type="xs:decimal"/>
<xs:element name="lng" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
感谢您的回复
干杯