When I change the ID value to alpha characters - it doesn't tell me the values are invalid...
course-details.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://in28minutes.com/courses"
xmlns:tns="http://in28minutes.com/courses" elementFormDefault="qualified">
<element name="GetCourseDetailsRequest">
<complexType>
<sequence>
<element name= "id" type="integer"></element>
</sequence>
</complexType>
</element>
</schema>
Request.xml I expect an error to show on the <id> line...
<?xml version="1.0" encoding="UTF-8"?>
<GetCourseDetailsRequest xmlns="http://in28minutes.com/courses"
xsi:schemaLocation="http://in28minutes.com/courses course-details.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id>abc</id> <!-- numbers -->
</GetCourseDetailsRequest>
The files are in the same folder - so not sure why this doesn't work:
You likely don't have the Validation builder on the project, or aren't letting the project build (which would automatically validate your XML files).
Open the project's Properties dialog and go to the Validation page. The option to add it should be there.
EDIT: You should also be able to right-click on the file and manually Validate it.
Related
Im triying to implement a simple BPEL process that should be able to accept as an input an element defined in an external XSD.
Im using Eclipse Oxigen.2 Release (4.7.2) and the Eclipse BPEL designer 1.05 Final, also i'm running the BPEL process in Apache ODE Server 1.3.7.
To achieve this im importing the XSD in the BPEL generated WSDL, but when i include this tag the apache ODE Console doesnt show the process if i quit the import tag the process is showed in the console and runs correctly.
As BPEL2.0 is based in WSDL1.1 i was following the WSDL1.1 specification in the Authoring Style part, but it seems to be an error in the example, because they use the wsdl:import to import a XSD. Trying to import the XSD in this way raise a validation error in eclipse.
I found this answer that points to this link that states the error in WSDL1.1 specification:
Some examples in WSDL 1.1 incorrectly show the WSDL import statement
being used to import XML Schema definitions. The Profile clarifies use
of the import mechanisms to keep them consistent and confined to their
respective domains. Imported schema documents are also constrained by
XML version and encoding requirements consistent to those of the
importing WSDL documents.
R2001 A DESCRIPTION MUST only use the WSDL "import" statement to
import another WSDL description.
R2803 In a DESCRIPTION, the namespace attribute of the wsdl:import
MUST NOT be a relative URI.
R2002 To import XML Schema Definitions, a DESCRIPTION MUST use the XML
Schema "import" statement.
R2003 A DESCRIPTION MUST use the XML Schema "import" statement only
within the xsd:schema element of the types section.
R2004 In a DESCRIPTION the schemaLocation attribute of an xsd:import
element MUST NOT resolve to any document whose root element is not
"schema" from the namespace "http://www.w3.org/2001/XMLSchema".
R2009 An XML Schema directly or indirectly imported by a DESCRIPTION
MAY include the Unicode Byte Order Mark (BOM).
R2010 An XML Schema directly or indirectly imported by a DESCRIPTION
MUST use either UTF-8 or UTF-16 encoding.
R2011 An XML Schema directly or indirectly imported by a DESCRIPTION
MUST use version 1.0 of the eXtensible Markup Language W3C
Recommendation.
So with the above information, rigth now i have:
1. XSD Sxhema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ccts="urn:un:unece:uncefact:documentation:2"
targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="2.1">
<!-- ===== Imports ===== -->
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
schemaLocation="../common/UBL-CommonAggregateComponents-2.1.xsd"/>
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
schemaLocation="../common/UBL-CommonBasicComponents-2.1.xsd"/>
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
schemaLocation="../common/UBL-CommonExtensionComponents-2.1.xsd"/>
<!-- ===== Element Declarations ===== -->
<xsd:element name="OrderCancellation" type="OrderCancellationType">
<xsd:annotation>
<xsd:documentation>This element MUST be conveyed as the root element in any instance document based on this Schema expression</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- ===== Type Definitions ===== -->
<xsd:complexType name="OrderCancellationType">
<xsd:annotation>
<xsd:documentation>
<ccts:Component>
<ccts:ComponentType>ABIE</ccts:ComponentType>
<ccts:DictionaryEntryName>Order Cancellation. Details</ccts:DictionaryEntryName>
<ccts:Definition>A document used to cancel an entire Order.</ccts:Definition>
<ccts:ObjectClass>Order Cancellation</ccts:ObjectClass>
</ccts:Component>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element ref="cbc:IssueDate" minOccurs="1" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
<ccts:Component>
<ccts:ComponentType>BBIE</ccts:ComponentType>
<ccts:DictionaryEntryName>Order Cancellation. Issue Date. Date</ccts:DictionaryEntryName>
<ccts:Definition>The date, assigned by the sender, on which this document was issued.</ccts:Definition>
<ccts:Cardinality>1</ccts:Cardinality>
<ccts:ObjectClass>Order Cancellation</ccts:ObjectClass>
<ccts:PropertyTerm>Issue Date</ccts:PropertyTerm>
<ccts:RepresentationTerm>Date</ccts:RepresentationTerm>
<ccts:DataType>Date. Type</ccts:DataType>
</ccts:Component>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element ref="cbc:IssueTime" minOccurs="0" maxOccurs="1">
<xsd:annotation>
...
</xsd:annotation>
</xsd:element>
<xsd:element ref="cbc:Note" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
...
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
2. Generated WSDL of BPEL Process
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://br.ufsc.das.ubl"
xmlns:ubl="urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2"
xmlns:vprop="http://docs.oasis-open.org/wsbpel/2.0/varprop"
xmlns:wsdl="http://service.endpoint.br.ufsc.das/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
name="OrderingUBL"
targetNamespace="http://br.ufsc.das.ubl">
<!--
Added XSD namespace
xmlns:ubl="urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2"
-->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TYPE DEFINITION - List of types participating in this BPEL process
The BPEL Designer will generate default request and response types
but you can define or import any XML Schema type and use them as part
of the message types.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<plnk:partnerLinkType name="IntegratorEndPoint_PLT">
<plnk:role name="IntegratorEndPoint_Role" portType="wsdl:IntegrationEndPointImpl"/>
</plnk:partnerLinkType>
<import location="file:/C:/my/path/IntegrationEndpoint.wsdl" namespace="http://service.endpoint.br.ufsc.das/"/>
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://br.ufsc.das.ubl">
<!--Importing the XSD file-->
<import
namespace="urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2"
schemaLocation="file:/C:/UBL-2.1/xsd/maindoc/UBL-OrderCancellation-2.xsd" />
<element name="OrderingUBLRequest">
<complexType>
<sequence>
<!-- Defining the Type of element OrderingUBLRequest
to be the element in the imported XSD
-->
<element name="input" type="ubl:OrderCancellationType" />
</sequence>
</complexType>
</element>
<element name="OrderingUBLResponse">
<complexType>
<sequence>
<element name="result" type="string"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MESSAGE TYPE DEFINITION - Definition of the message types used as
part of the port type defintions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<message name="OrderingUBLRequestMessage">
<part element="tns:OrderingUBLRequest" name="payload"/>
</message>
<message name="OrderingUBLResponseMessage">
<part element="tns:OrderingUBLResponse" name="payload"/>
</message>
<!--
.
. All the other WSDL tags
.
-->
</definitions>
QUESTION
Am I missing something importing the XSD in the WSDL BPEL file and run it in Apache ODE?
I am pretty new to xsds, and currently the xsd I am using is only validating on some machines. It works on my local machine, but when I try doing this on a machine where there are some proxies or firewalls, it no longer works. The schemas I am using are used locally, though.
Here is the error I get when the xsd schema is attempting to validate:
src-resolve: Cannot resolve the name 'xenc:EncryptedDataType' to a(n)
'type definition' component.
Which comes from this code:
boolean validate(URL schemaUrl) {
SchemaFactory schemaFactory = SchemaFactory
.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = null;
try {
schema = schemaFactory.newSchema(schemaUrl); //this is where the exception is thrown
} catch (SAXException e) {
//exception is caught here
return false;
}
//... more code here
}
The error has the same stack trace as this one:
SAXParseException; src-resolve: Cannot resolve the name '...' to a(n) 'type definition' component
I have my main xsd that begins something like this:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:tns="http://customization.elster.com/shipment"
targetNamespace="http://customization.client.com/introduction"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
version="1.1" >
<xs:import namespace="http://www.w3.org/2001/04/xmlenc#" schemaLocation="xenc-schema.xsd"/>
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
in this main XML I need the "xenc:EncryptedDataType"
<xs:complexType name="NamedEncryptedDataType">
<xs:complexContent>
<xs:extension base="xenc:EncryptedDataType">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
which is defined in the xenc-schema.xsd (which is in the same folder as my main xsd)
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSchema 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd"
[
<!ATTLIST schema
xmlns:xenc CDATA #FIXED 'http://www.w3.org/2001/04/xmlenc#'
xmlns:ds CDATA #FIXED 'http://www.w3.org/2000/09/xmldsig#'>
<!ENTITY xenc 'http://www.w3.org/2001/04/xmlenc#'>
<!ENTITY % p ''>
<!ENTITY % s ''>
]>
<schema xmlns='http://www.w3.org/2001/XMLSchema' version='1.0'
xmlns:xenc='http://www.w3.org/2001/04/xmlenc#'
xmlns:ds='http://www.w3.org/2000/09/xmldsig#'
targetNamespace='http://www.w3.org/2001/04/xmlenc#'
elementFormDefault='qualified'>
<import namespace='http://www.w3.org/2000/09/xmldsig#'
schemaLocation='xmldsig-core-schema.xsd'/>
in this xenc-schema, there is the culprit data type:
<element name='EncryptedData' type='xenc:EncryptedDataType'/>
<complexType name='EncryptedDataType'>
<complexContent>
<extension base='xenc:EncryptedType'>
</extension>
</complexContent>
</complexType>
I've tried to keep this question shorter, let me know if more information is needed, thanks for reading.
The best way to diagnose these sort of problems is to install an HTTP debugger. For e.g., Fiddler is a good one that should work for you. It should tell you what resource is resolved externally (on the Internet).
In your case, most likely the culprit is the DTD in your xenc-schema.xsd file. To quickly prove it, simply get rid of any embedded DTDs. Once you prove the issue, you may choose to simply keep the edited XSDs, or use a custom EntityResolver, or see if your particular library has some sort of property you can set to disable DTD processing (which is really useless here).
What is the best way to convert this XML into Java objects?
<entity>
<customers id=2 other="data">
<customer name="john">testData1</customer>
<customer name="jenny">testData2</customer>
<customer name="joe">testData3</customer>
<customer name="joanna">testData4</customer>
</customers>
</entity>
Is it best to use a custom XMLAdapter with a HashMap to convert multiple xml rows of <customer>? I'm not sure if the XMLAdapter is the proper use case for this scenario. Any ideas would be appreciated.
Since the nesting isn't very deep, you could just have Entity, Customer classes and then use these annotations for the mapping in the entity class:
#XmlElementWrapper(name="customers")
#XmlElement(name="customer")
public void setCustomers(List<Customer> customers) {
this.customers= customers;
}
References:
XmlElementWrapper
Best approach, in my opinion, would be to write an xsd file to validate against your xml. You can use that to generate your java classes using xjc which comes bundled with Java. This should get you there.
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:NameOfNamespace="http://enter.your.namespace.here"
targetNamespace="http://enter.your.namespace.here"
attributeFormDefault="unqualified"
elementFormDefault="qualified">
<complexType name="customer">
<simpleContent>
<extension base="string">
<attribute name="name"/>
</extension>
</simpleContent>
</complexType>
<complexType name="customers">
<sequence>
<element name="customer" type="NameOfNamespace:customer"/>
</sequence>
<attribute name="id" type="positiveInteger"/>
<attribute name="other"/>
</complexType>
<complexType name="entity" >
<sequence>
<element name="customers" type="NameOfNamespace:customers" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
<element name="entity" type="NameOfNamespace:entity"/>
</schema>
Open a command prompt to the folder where you put your xsd file, and then generate java code you'll just need to type:
$ xjc nameOfSchemaFile.xsd
assuming your java 'bin' folder is in your path. The classes generated will be created in folder with the same name as your targetNamespace.
Using these you can follow the instructions in Naimish's example JAXB Hello World Example
I want to generate the POJOs using the xml-binding with a different hierarchy that I have right now.
Now I have an xsd like this one:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://manueldoncel.com" xmlns:tns="http://manueldoncel.com" elementFormDefault="qualified">
<!-- Base element that any element uses / extends -->
<complexType name="baseElement" abstract="true">
<sequence>
<element name="attributes" type="anyType" minOccurs="0" />
</sequence>
<attribute name="id" type="string" />
</complexType>
<complexType name="Square">
<complexContent><extension base="tns:baseElement" /></complexContent>
</complexType>
<complexType name="Triangle">
<complexContent><extension base="tns:baseElement" /></complexContent>
</complexType>
</schema>
An a xjb like this;
<?xml version="1.0"?>
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jxb:extensionBindingPrefixes="xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="figures.xsd" node="/xs:schema">
<jxb:globalBindings>
<xjc:simple />
<xjc:superClass name="org.manuel.metadata.Figure"/>
</jxb:globalBindings>
</jxb:bindings>
</jxb:bindings>
But, I would like to have a better hierarchy with this approach
public abstract class Figure {
// some methods for all the figures
}
public abstract class ThreeSideFigure extends Figure {
.... // some methods for only the Three side Figures
}
So, the Triangle POJO generated from the XSD should extend from ThreeSideFigure rather than from Figure.
In this particular xsd I only put 2 figures, but I can have much more. I would like to be able to specify in the xjb that all the complexType should extends from Figure but only a few of them, should extends from ThreeSideFigure.
Do you know how the xjb should look like?
I don't think the Metro JAXB RI extensions will let you do that.
From the 2.2.7 documentation:
3.1.3. Extending a Common Super Class
The <xjc:superClass> customization allows you to specify the fully
qualified name of the Java class that is to be used as the super class
of all the generated implementation classes. The <xjc:superClass>
customization can only occur within your <jaxb:globalBindings>
customization on the <xs:schema> element
That said, the answer to XJC superinterface and superclass only for all classes? suggests that you may be able to do it with 3rd party extensions. There are some details about plugins in the documentation.
I am not master in XML and XSD.
Just want to know how I can merge more than one XSD file to one XSD file?
Thanks in Advance.
You can use import (different namespace) and include (same namespace) multiple times. redefine can also be used multiple times. It depends on what you mean by "merge."
See also http://www.herongyang.com/XML-Schema/Multiple-XSD-Schema-Document-Include-Redefine-Import.html or http://msdn.microsoft.com/en-us/library/ee254473%28v=bts.10%29.aspx.
Edit: redefine can be used multiple times (similar to include).
Examples (validated in Eclipse) follow. I used different namespace (as the "merging" target namespace) and element names where necessary:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/m"
xmlns:tns="http://www.example.org/m" elementFormDefault="qualified">
<!-- import: different (i.e. not target) namespace -->
<import namespace="http://www.example.org/a" schemaLocation="so20046640a.xsd"/>
<import namespace="http://www.example.org/b" schemaLocation="so20046640b.xsd"/>
<!-- include: same namespace -->
<include schemaLocation="so20046640c.xsd"/>
<include schemaLocation="so20046640d.xsd"/>
<!-- redefine: same namespace -->
<redefine schemaLocation="so20046640e.xsd"/>
<redefine schemaLocation="so20046640f.xsd"/>
</schema>
...a.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/a"
xmlns:tns="http://www.example.org/a" elementFormDefault="qualified">
<element name="a" type="int"/>
</schema>
...b.xsd: Same as ...a.xsd but target namespace .../b
...c.xsd: Same as ...a.xsd but target namespace .../m
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/m"
xmlns:tns="http://www.example.org/m" elementFormDefault="qualified">
<element name="a" type="int"/>
</schema>
...d.xsd: Same as ...c.xsd but element name b.
...e.xsd: Same as ...c.xsd but element name e.
...f.xsd: Same as ...c.xsd but element name f.