What is wrong with this XPath Expression in a jaxb bindings file? - xpath

trying to evaluate the XPath expression
/xs:schema/xs:element[#name='StrikeOptionReservationSummaryData']/xs:complexType
with the following document produces an XPathExpressionException
<xs:schema>
<xs:element name="StrikeOptionReservationSummaryData">
<xs:complexType>
...
</xs:complexType>
</xs:element>
<xs:schema>
The error from from xjc is [ERROR] XPath error: null
What is wrong with this?

It's a lousy diagnostic, but perhaps you didn't give the XPath processor a binding for the namespace prefix "xs"?

Related

BizTalk BlobStorageAdapter - Promote Blob Metadata as BizTalk properties

I'm using the AzureBlobStorage adapter in BizTalk 2020 and to receive blobs from Azure Blob Storage. The blobs have metadata which I want to use within my orchestration. So I created and deployed a schema containing the metadata keys as elements.
Within the receive location I entered the "Namespace for blob metadata" with the namespace of my schema and checked the checkbox "Promote metadata properties"
Unfortunately I'm getting the following error: "Loading property information by list by namespace failed or property not found in the list. Verify that the schema is deployed properly."
Schema:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://POC.Test.AzBlobMetadata.AzLaParameters" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://POC.Test.AzBlobMetadata.AzLaParameters" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<b:schemaInfo schema_type="AzLaParameters" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
<xs:element name="MetaData">
<xs:complexType>
<xs:sequence>
<xs:element name="la_name" type="xs:string" />
<xs:element name="la_runid" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Receive Location / Adapter configuration:

xmlbeans-maven-plugin not generating getters for Lists

I'm currently trying to build a legacy project which has been migrated from Ant to Maven. This project uses the xmlbeans-maven-plugin to build java classes from .xsd source files. Everything works fine until a get...List() method gets called. All List-getters seem to be missing. All the information I could find points to a Java version being used that does not support Lists. The solution that worked for most people was changing the javaSource tag in the plugin configuration to 1.5. This did not solve my problem.
The relevant part of my pom.xml currently looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<configuration>
<javaSource>1.8</javaSource>
<schemaDirectory>src/main/xsd</schemaDirectory>
</configuration>
</plugin>
Another stackoverflow thread (Maven2:List return type methods not getting generated from .xsd files while using xmlbeans plugin), from 2011 mind you, suggests to set the Java version to 1.5 instead. This gives me another error:
Failed to execute goal org.codehaus.mojo:xmlbeans-maven-plugin:2.3.3:xmlbeans (default) on project ...: XmlBeans compile failed:
xml ErrorLoading schema file ...
xml ErrorLoading schema file ...
xml ErrorLoading schema file ...
xml ErrorLoading schema file ...
xml ErrorLoading schema file ...
The solution for this problem I found here tells me this is a problem with Java 11 and that I should set the Java version to 1.8.
Here's a snippet of one of the .xsd files:
<xs:element name="DbcFile" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="path" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
This should generate a method called getDbcFileList(). However, as you can see from this error message, it does not do that:
... cannot find symbol
symbol: method getDbcFileList()
It does generate getDbcFileArray(). I have tried a lot of combinations of changing Java versions, removing the build folder every time to get a clean build, you name it. I'm honestly out of ideas.
I'm using Maven 3.6.3 and OpenJDK 13.0.2+8_2. I'm running maven commands from IntelliJ 2020.1. The only thing I haven't tried is downgrading my JDK, but I feel like that won't make a difference.
I solved it. The solution was to downgrade to JDK 1.8, for some reason.
I got this error when upgrading from JDK 1.8 to JDK 11. The xmlbeans-maven-plugin is old but if you have to stick with it then the solution is to add following attributes to <configuration> section for the plugin in pom.xml:
<noJavac>true</noJavac>
<javaSource>1.6</javaSource>
The author was close to solution but <javaSource> attribute alone is not enough. Setting <noJavac> prevents xmlbeans from calling compilation with argument "-source" pointing to possibly no longer supported Java versions, in my case 1.4.
I see the OP linked the thread where I found solution, but back then the part about javac was missing: https://github.com/ethercis/openehr-java-libs/issues/1#issuecomment-880253566.

Generating soap service and POJO classes from xsd and wsdl

I am creating a soap service by consuming one wsdl and multiple xsd files. The xsd files are included in my wsdl. I have tried with jaxws and cxf plugins using maven. Both the plugins are throwing error/exception while parsing the wsdl.
below is the error from jaxws:
[ERROR] Invalid wsdl:operation "insertSubscriber": its a document-literal operation, message part must refer to a schema element declaration
CXF dies without throwing any error description.
The jxc framework creates the classes from xsd files but they are of no use because I have to create endpoints manually and the linking of the classes is already defined in my wsdl.
I have also C++ gsoap client which uses the same wsdl and xsds using which I can create my soap service, But I want to migrate my service to a java application. How do I fix the above problem?
wsdl snippet:
<wsdl:import namespace="MyDomain/mytypes" location="MyTypes1.xsd"/>
<xsd:complexType name="insertSubscriberRequest">
<xsd:sequence>
<xsd:element name="insertAddressList" type="mytypes:InsertAddressList"/>
</xsd:sequence>
</xsd:complexType>
<wsdl:message name="insertSubscriberRequest">
<wsdl:part name="insertSubscriberRequest" type="tns:insertSubscriberRequest"/>
</wsdl:message>
<!--wsdl operation-->
<wsdl:portType name="myService">
<wsdl:operation name="insertSubscriber">
<wsdl:input message="tns:insertSubscriberRequest"/>
<wsdl:output message="tns:insertSubscriberResponse"/>
</wsdl:operation>
</wsdl:portType>
<!--soap operation-->
<wsdl:operation name="insertSubscriber">
<soap:operation soapAction="MyDomain/mytypes/insertSubscriber"/>
<wsdl:input>
<soap:body use="literal" namespace="MyDomain/mytypes"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="MyDomain/mytypes"/>
</wsdl:output>
</wsdl:operation>
snippet from MyTypes1.xsd:
<xs:complexType name="InsertAddressList">
<xs:annotation>
<xs:documentation>Definition of a list of Account IDs for Insert operation</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="accountId" type="MyType2:sdsAccountId" minOccurs="10" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
snippet from MyTypes2.xsd
<xs:simpleType name="sdsAccountId">
<xs:annotation>
<xs:documentation>Definition of Account ID parameter</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="26"/>
<xs:pattern value="([0..9]){1,26}"/>
</xs:restriction>
</xs:simpleType>
I verified the WSDL file and there was an import error. Actually, It was importing the xsds two times once in the wsdl:definitions and once in the xsd:schema. removing the import from the wsdl:definitions worked for me,
With wsimport I am facing the same issue, but it is working with cxf.

Why am I getting different validation between an XSD regex with Nokogiri and normal Ruby regular expressions?

I have an XSD schema that includes a rule for a specific field to match the following regex:
\d{8}[\-]?[A-Za-z]{0,3}
Using irb, I can test with this regex and the following strings all match, which is correct:
12345678
12345678-
12345678-abc
12345678abc
When I attempt to validate some XML against this XSD, I get slightly different behaviour:
Passes:
12345678-
12345678-abc
12345678abc
Fails:
12345678
And here is a mimimal XSD/XML files that reproduces this:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="codeType">
<xs:restriction base="xs:token">
<xs:pattern value="\d{8}[\-]?[A-Za-z]{0,3}"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element type="codeType" name="code"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And XML:
<?xml version="1.0" encoding="UTF-8"?>
<test>
<code>11034755</code>
</test>
And running this with
xmllint --schema test.xsd test.xml
Gives
Element 'code': [facet 'pattern'] The value '11034755' is not accepted by the pattern '\d{8}[\-]?[A-Za-z]{0,3}'
While XML schema does not have full regular expressions, this should be valid I think. What am I not understanding when it comes to regular expressions in XSD files in this particular case with regards to '?' ?
Using Rubular to test /\d{8}-?(?:[a-zA-Z]{3})?/ I get hits for all strings.
Alternately /\d{8}[a-zA-Z-]*/, /\d{8}[a-z-]*/i, and /\d{8}[a-z-]{0,4}/i work also.
You can use {0,3} or {,3} so those might help.

c# XDocument Xsd pattern validation with character $

I have a problem with c# XDocument XSD validation.
The following file is validated well by Xml Spy, but not by .Net (c#)
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Simple.xsd">
<Var Name="$Toto"/>
</Root>
Schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Var">
<xs:complexType>
<xs:attribute name="Name" type="ST_VariableIdentifier" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="ST_VariableIdentifier">
<xs:restriction base="xs:string">
<xs:pattern value="$[a-z,A-Z]*"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
An idea?
This should work!
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Var">
<xs:complexType>
<xs:attribute name="Name" type="ST_VariableIdentifier" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="ST_VariableIdentifier">
<xs:restriction base="xs:string">
<xs:pattern value="[$][a-z,A-Z]*"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Just to add to the existing answer. This is actually a known 'bug' in the .Net implementation of the W3C specs (acknowledged here on Connect, but Won't fix).
MSDN provides more information (here), together with the workaround mentioned above.
The System.Xml implementation of the World Wide Web Consortium (W3C)
Recommendations for XML Schemas uses the RegEx class to perform
pattern matching of regular expressions. In some cases, the behavior
recommended by W3C differs from the RegEx class behavior. The
following are the known cases where the System.Xml implementation of
pattern matching differs from the W3C specification:
According to the W3C for XML Schema specification, the dollar sign ($)
should be treated as a regular character. However, the System.Xml
validation interprets a dollar sign in the xs:pattern as an
end-of-line anchor. The possible workaround is to replace $ with [$].
If your pattern is already in brackets, such as [abc$], it is not
necessary to make any changes.

Resources