Sample Schema:
<xs:complexType name="ClassTest">
<xs:element name="Name" type="xs:string" />
<xs:element name="Class" type="xs:string" />
<xs:any namespace="##other" processContents="lax"maxOccurs="Unbound" />
Sample XML:
<ClassTestxmlns="http://schooltest.com">
<Name>AAA</Name>
<Class>3</Class>
<ns:maths>33</ns:maths>
<ps:english>44<ps:english>
</ClassTest>
How do I refer the elements maths and english which have different namespace to target namespace?
Thanks.
As your question is tagged as XSLT 2.0, you could also consider to use a wildcard e.g. *:maths and *:english, that selects elements with local name maths respectively english in any namespace.
How do I refer the elements maths and english which have different
namespace to target namespace.
Because nothing is known in advance about the namespace and name of such an element, it is only safe to select them without using any particular name or namespace:
/x:ClassTest/*[not(self::x:Name or self::x:Class)]
Where the prefix "x:" must be bound to the namespace "http://schooltest.com" .
This expression selects any element that is a child of the top element x:ClassTest and is not one of the elements x:Name or x:Class. When applied on the provided XML document, it selects both the ns:maths and the ps:english elements.
Related
I have problem with geting full response from SOAP WS in Progress OpenEdge.
"bprowsdldoc" app generated full call and output structure to DATASET, but in DATASET I have only last element of "document" type.
Response looks like this:
<GetDocumentsResponse>
<documentsCount>3</documentsCount>
<document>
<content filename="file1.xml" mime="application/xml"> [base64] </content>
</document>
<document>
<content filename="file2.xml" mime="application/xml"> [base64] </content>
</document>
<document>
<content filename="file3.xml" mime="application/xml"> [base64] </content>
</document>
<documentsInfo>All done.</documentsInfo>
</GetDocumentsResponse>
My goal is to get all "document" elements in output DATASET (count of 3 is only a sample) or get full response XML as LONGCHAR.
Any help will be appreciated.
EDIT:
Web service is internal in my company and calling it requiers VPN connection, so I can't give You link.
But bprowsdldoc generated a code like this for method "GetDocuments":
DEFINE VARIABLE dateStart AS DATE NO-UNDO.
DEFINE VARIABLE dateEnd AS DATE NO-UNDO.
DEFINE VARIABLE documentsCount AS INT64 NO-UNDO.
DEFINE TEMP-TABLE document NO-UNDO
FIELD docId AS CHARACTER.
DEFINE TEMP-TABLE content NO-UNDO
FIELD filename AS CHARACTER
XML-NODE-TYPE "ATTRIBUTE"
FIELD mime AS CHARACTER
XML-NODE-TYPE "ATTRIBUTE"
FIELD content_Text AS RAW
XML-NODE-TYPE "TEXT"
FIELD document_id AS RECID
XML-NODE-TYPE "HIDDEN" .
DEFINE DATASET documentDset
XML-NODE-TYPE "HIDDEN"
FOR document, content
PARENT-ID-RELATION RELATION1 FOR document, content
PARENT-ID-FIELD document_id.
DEFINE VARIABLE documentsInfo AS CHARACTER NO-UNDO.
RUN GetDocuments IN hDocumentHandlingPort(INPUT dateStart, INPUT dateEnd, OUTPUT documentsCount, OUTPUT DATASET documentDset, OUTPUT documentsInfo).
After calling this method I get proper response for variables documentsCount and documentsInfo but in TEMP-TABLE content I got only one row with document element from response (there should be 3 for dates from 2017-03-16 to 2017-03-16 as ine example response on the top of my post).
Response in WSDL looks like this:
<xs:element name="GetDocumentsResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="documentsCount" type="xs:long"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="document" type="ns1:documentType"/>
<xs:element minOccurs="0" name="documentsInfo" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
I think that problem may be related to maxOccurs attribute of element document - it's unbounded and maybe there should be some numeric value...
Can You help mi handle this problem?
Due to defect PSC00323593, described in knowledge base, this situation is a bug. But there is always light in the dark, so there is also workaround for it:
Use the WSDL Analyzer (bprowsdldoc) with -show100style parameter to
generate documentation. Using the older syntax works as desired,
returning all expected records.
In the scenario encountered, the alternate documentation uses type
LONGCHAR for parameters. It was then possible to combine code from
original documentation (specifically the TEMP-TABLE and DATASET
definitions) with the code from the -show100style documentation. The
READ-XML method was used to read the LONGCHAR output parameter into
the DATASET.
or
Add APPEND option to the DATASET parameter.
You can find full article here.
I am a beginner in using XSLT so I am not sure if this is even feasible. I really appreciate your help.
XSLT to transform from one format to another.
The source XML does not have the type.
I need to reference the XSD to get the type for the given element.
<match="*[not(*)]">
<elementName>
<key>
<xsl:value-of select="name()"/>
</key>
<type>
if (name() matches name =id in xsd file"
// if name = id matches name = id in xsd get type=String
<type>
This is sample XSD:
<xs:complexType name = "test">
<xs:sequence
<xs:element name="id" type="xs:string"/>
</xs:sequence>
</xscomplexType>
Using an XSLT 2.0 schema-aware transformation, you can write:
<xsl:import-schema>
... schema goes here, either inline or by reference ...
</xsl:import-schema>
<xsl:template match="element(id, xs:string)">
...
</xsl:template>
The normal way of using this assumes that you write your stylesheet knowing what is in the schema. Saxon has extended this with extension functions allowing you to discover what is in your schema. For example:
<xsl:variable name="type" select="saxon:type-annotation()"/>
<key><xsl:value-of select="name()"/></key>
<type>Q{<xsl:value-of select="namespace-from-QName($p)||"}"||local-name-from-QName($type)"/></type>
See the saxon:type-annotation and saxon:schema extension functions at http://www.saxonica.com/documentation/index.html#!functions/saxon
Analysing a schema document from XSLT directly is possible in theory but it's an enormous amount of work to get it right, if you're going to handle things such as xs:include/import/redefine, named types and anonymous types, global and local element declarations, substitution groups, etc. etc.
Yet another approach is to analyse the "precompiled schema" in XML format (SCM) which you can output from Saxon, which eliminates many of these difficulties.
Other products also offer APIs to access the schema, but there is no real standard.
I have an xml schema from a third party web service provider.
<xsd:element name="Student">
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="1"/>
<xs:element name="Address" type="xs:string" minOccurs="0"/>
<xs:element name="Gender" type="xs:string" minOccurs="1"/>
</xs:sequence>
</xsd:element>
I am going to consume the dataset returns from this web service in my C# code. Since Address has the minOccurs set to 0, it means the web service can either return value for Address or not returning Address. For example:
Scenario 1:
<Student>
<Name>Eddie</Name>
<Gender>Male</Gender>
</Student>
Scenario 2:
<Student>
<Name>Alice</Name>
<Address>White House</Address>
<Gender>Female</Gender>
</Student>
Scenario 3:
<Student>
<Name>Jenny</Name>
<Address></Address>
<Gender>Female</Gender>
</Student>
May I know how do I check, in my C# code whether the web service return Address.
For result set from Scenario 1, I would like to hide the contact Section from my form all together.
For result set from Scenario 2, I would like to display the contact Section on my form, and have the address display.
For result set from Scenario 3, I would like to display the contact Section on my form, but have the Address field in the contact section set to "Address not provided".
May I know could I achieve that?
I know we can check whether the elements hasvalue or isnull. But how do we check whether the result returned by the web service contains the element (Scenario 1)?
After some research and testing done, I think I can have something like this:
bool ShowContactFlag = false;
if (Dataset.Tables[0].Columns.Contains("Address"))
{
ShowContactFlag = true;
}
else
{
ShowContactFlag = false;
}
I'm new to web services world, and I've seen in different tutorials that some of them use xs:string for data type and some use xsd:string for messages in w3schools.com tut is as below:
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
And for example in Apress Beginning PHP and MySQL is as the following code:
<message name="getTermResponse">
<part name="value" type="xsd:string"/>
</message>
What is the differences between them? which one to use when?
xs:string is an example of a qualified name in XML. The xs part refers to a namespace declaration on the same element or a parent element. Most likely, there's an xmlns:xs=http://www.w3.org/2001/XMLSchema declaration.
xsd:string is exactly the same thing, assuming that the declaration is xmlns:xsd=http://www.w3.org/2001/XMLSchema. foo:string would also be the same, if the declaration were xmlns:foo=http://www.w3.org/2001/XMLSchema.
In other words, the prefix does not matter. It is an alias for the namespace. If the namespaces are the same, and the local names are the same, then the two qualified names are the same.
I am trying to forward ArrayList as the parameter from .Net environment to the webservice file generated by Axis2. But it's displaying the type as follows in the WSDL file
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="myMethod" nillable="true" type="xs:anyType" />
</xs:sequence>
</xs:complexType>
Also, if I test the WSDL file using the soapPUI, it's displaying the following message in the Form "Type : [{http://www.w3.org/2001/XMLSchema}anyType] is not supported by the Form Editor"
And if I manually forward the details in the XML file then it's displaying the following error message : org.apache.axiom.om.impl.llom.OMTextImpl cannot be cast to java.lang.String
What am I supposed to do to fix this issue ?
You're not passing an array list but rather an array of objects, and I don't believe such an array is serializable:
Dim resultString As String = MyService.myMethod(myAL.toArray)
What type is the myMethod argument?