Using XPath on JDOM

Hi,
I am looking for am elegant way to extract data from JDOM.
I tried using org.jdom.xpath.XPath but am not sure what jars I need or what needs to be initialized before XPath works.
While execution the XPath.newInstance fails..
Element result = data.getRootElement();//partner_results
try{
XPath xpath = XPath.newInstance("/partner_results/partner_result[@name=\"Amazon\"]");
result = (org.jdom.Element)xpath.selectSingleNode(data);
}catch(Exception e){}
Is there an easy way to get this ball rolling. There does not seem to be enough documentation on using XPath on JDOM
Any pointers would be really useful.
thanks
M

Thanks for suggesting Jaxen. I am now able to pull most of the data out of JDOM.
However, here is a issue I am facing with following snippet of XML. What is the correct XPath expression to extract the node MultiOperationResponse?
- <partner_results>
- <partner_result id="3" name="Amazon">
<status code="200">OK</status>
- <data>
+ <MultiOperationResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-07-26">
</MultiOperationResponse>
</data>
<partner_result>
<partner_results>
Here is the XPath expression
     XPath expr = new JDOMXPath("/partner_results/partner_result[@name=\"Amazon\"]/data/MultiOperationResponse");
     expr.addNamespace("","http://webservices.amazon.com/AWSECommerceService/2005-07-26");
I get a null when I apply the
result = (org.jdom.Element)expr.selectSingleNode(data);
Where data is the JDOM tree.
However, I can extarct the <data> node.
What is it that I am missing?
thanks a bunch
M

Similar Messages

  • SSMS 2012:FOR XML PATH Using XPath Node Tests-Columnn name 'test()' contains an invalid XML identifier as required by FOR XML?

    Hi all,
    I am learning XPATH and XQUERY from the Book "Pro T-SQL 2008 Programmer's Guide" written by Michael Coles, (published by apress). I copied the Code Listing 12-8 FOR XML PATH Using XPath Node Tests (listed below) and executed it in my
    SQL Server 2012 Management Studio:
    --Coles12_8.sql // saved in C:/Documemnts/SQL Server Management Studio
    -- Coles Listing 12-8 FOR XML PATH Using XPATH Node Tests
    -- Retrieving Name and E-mail Addresses with FOR XML PATH in AdvantureWorks
    -- 16 March 2015 0935 AM
    USE AdventureWorks;
    GO
    SELECT
    p.NameStyle AS "processing-instruction(nameStyle)",
    p.BusinessEntityID AS "Person/@ID",
    p.ModifiedDate AS "comment()",
    pp.PhoneNumber AS "test()",
    FirstName AS "Person/Name/First",
    MiddleName AS "Person/Name/Middle",
    LastName AS "Person/Name/Last",
    EmailAddress AS "Person/Email"
    FROM Person.Person p
    INNER JOIN Person.EmailAddress e
    ON p.BusinessEntityID = e.BusinessEntityID
    INNER JOIN Person.PersonPhone pp
    ON p.BusinessEntityID = pp.BusinessEntityID
    FOR XML PATH;
    I got the following error message:
    Msg 6850, Level 16, State 1, Line 2
    Column name 'test()' contains an invalid XML identifier as required by FOR XML; '('(0x0028) is the first character at fault.
    I have no ideas why I got this error message.  Please kindly help and advise me how to resolve this error.
    Thanks in advance,  Scott Chang

    Hi Michelle, Thanks for your nice response.
    I corrected the mistake and executed the revised code. It worked nicely.
    I just have one question to ask you about the appearance of the xml output of my Co;les12_8.sql:
    <row>
    <?nameStyle 0?>
    <Person ID="1" />
    <!--2003-02-08T00:00:00-->697-555-0142<Person><Name><First>Ken</First><Middle>J</Middle><Last>Sánchez</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="2" />
    <!--2002-02-24T00:00:00-->819-555-0175<Person><Name><First>Terri</First><Middle>Lee</Middle><Last>Duffy</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="3" />
    <!--2001-12-05T00:00:00-->212-555-0187<Person><Name><First>Roberto</First><Last>Tamburello</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="4" />
    <!--2001-12-29T00:00:00-->612-555-0100<Person><Name><First>Rob</First><Last>Walters</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="5" />
    <!--2002-01-30T00:00:00-->849-555-0139<Person><Name><First>Gail</First><Middle>A</Middle><Last>Erickson</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="6" />
    <!--2002-02-17T00:00:00-->122-555-0189<Person><Name><First>Jossef</First><Middle>H</Middle><Last>Goldberg</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="7" />
    <!--2003-03-05T00:00:00-->181-555-0156<Person><Name><First>Dylan</First><Middle>A</Middle><Last>Miller</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="8" />
    <!--2003-01-23T00:00:00-->815-555-0138<Person><Name><First>Diane</First><Middle>L</Middle><Last>Margheim</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="9" />
    <!--2003-02-10T00:00:00-->185-555-0186<Person><Name><First>Gigi</First><Middle>N</Middle><Last>Matthew</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="10" />
    <!--2003-05-28T00:00:00-->330-555-2568<Person><Name><First>Michael</First><Last>Raheem</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    <?nameStyle 0?>
    <Person ID="11" />
    <!--2004-12-29T00:00:00-->719-555-0181<Person><Name><First>Ovidiu</First><Middle>V</Middle><Last>Cracium</Last></Name><Email>[email protected]</Email></Person></row>
    <row>
    I feel this xml output is not like the regular xml output.  Do you know why it is diffrent from the regular xml xml output?  Please comment on this matter.
    Thanks,
    Scott Chang
    What do you mean by regular xml document? Are you referring to fact that its missing a root element? if yes it can be added as below
    USE AdventureWorks;
    GO
    SELECT
    p.NameStyle AS "processing-instruction(nameStyle)",
    p.BusinessEntityID AS "Person/@ID",
    p.ModifiedDate AS "comment()",
    pp.PhoneNumber AS "text()",
    FirstName AS "Person/Name/First",
    MiddleName AS "Person/Name/Middle",
    LastName AS "Person/Name/Last",
    EmailAddress AS "Person/Email"
    FROM Person.Person p
    INNER JOIN Person.EmailAddress e
    ON p.BusinessEntityID = e.BusinessEntityID
    INNER JOIN Person.PersonPhone pp
    ON p.BusinessEntityID = pp.BusinessEntityID
    FOR XML PATH('ElementName'),ROOT('RootName');
    replace ElementName and RootName with whatever name you need to set for element as well as the root element
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Using xpath expressions in Document-Builder

    Hi all
    we have re-designed our (existing) DDX-templates with the Document Builder in LC Workbench. The DDX templates are used to assemble PDFs with LC Assembler-Service.
    Now my question: Is it still possible to use XPath-expression in the DDX template? Please find our example below:
    The XPath expression works only if we copy&paste the DDX source code directly to the Assembler-Service property view (picture below). But referring the DDX-template doens't interpret the xpath path at run time (2nd picture below). Any help on that will be appreciated!
    Works (using DDX source code directly):
    Doesn't work (using DDX template):

    Hi,
    >
    I tried to get a portion of an XML by using XPath Expressions as follows:
    String xPathExpression =
    "declare namespace xq='http://inti.notariado.org/indices' " +
    "$this/xq:RULES/xq:RULE[@disabled]";
    I think any XPath expressions which use [] are not supported in stand alone
    version, but as this is not documented I could be wrong.
    Regards
    Arek

  • Using XPath for DOM traversal

    This question falls into the category of 'I know it's possible, I just need to find the idom in Java'.
    I'm coming from a MSFT world were the DOM-centric model of XML processing makes heavy use of XPATH for node selection. Basically using the method element.selectNodes(XPathExpresson) allows one to quickly extract the relevant subset of the parsed tree in the DOM as a nodeList. I've become accustomed to using XML for all strucutured storage that doesn't require a full database.
    The W3C DOM Level 3 spec supports evaluateExpression() for this purpose, but I can't believe that Java developers are still using tree traversal waiting for the spec to be implemented. I suppose that I could use getNodesByTagName(), but this is a chainsaw, and I need a scalpel. Anyway, I'm trying to figure out how, exactly, this gets done in Java.
    I figure the following are possibilities:
    1) It's in JAXP and I missed it
    2) One or more of the XML parsers supports XPATH as an extention
    3) There's a common package that sits on top of the DOM Document.
    4) There's a standard way to apply and XSLT methods to the DOM document
    5) Something I've never thought of.
    This is a generalized problem for me, so I can't rely on object serialization, Java-XML data mapping, etc. Any guidance would be greatly appreciated.

    I've written a Config file reader for XML in java,
    and it extracts values using XPath. This is
    some of the code you'll need:
    imports:
    import javax.xml.transform.TransformerException;
    import org.w3c.dom.*;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.apache.xerces.parsers.DOMParser;
    import org.apache.xpath.XPathAPI;
    import org.apache.xpath.objects.*;
    Document doc=....;
    * returns a single DOM Node from the config file.
    public Node getNode(String xpath) throws ConfigException {
    try {
    return XPathAPI.selectSingleNode(doc, xpath);
    } catch (TransformerException e) {
    throw new ConfigException("Can't find '"+xpath+"' ("+e.getMessage()+")");

  • Using XPath to create nodes

    Hi,
    Obviously the main use of XPath is to query the state of an XML document... the equivalent to a "select" statement in SQL.
    DOM4J has methods that allow you to use XPath as the equivalent to "insert" statements in SQL. You can specify an XPath like "/Hello/World/Value = 3" and apply this XPath to an XML document so that it creates something like this for you:
    <Hello>
    <World>
    <Value>3</Value>
    </World>
    </Hello>
    This is actually very useful for an investment banking application that I'm working on.
    The problem with DOM4J is that it doesn't handle attributes or conditionals well. If you specify
    /Hello[@name=2]/World = 3
    I would expect
    <Hello name=2>
    <World>3</World>
    </Hello>
    to be produced. Instead, it produces
    <Hello[@name=2]>
    <World>3</World>
    </Hello>
    These are all simple examples. What I'm doing in real life is using XPath to insert nodes into a complicated XML document that already has a lot of structure. I'm only adding one or two elements to big documents.
    Is there anything at all like this available in the JDK 1.5 release. I've had a good look, and XPath looks like it's only for queries. Is this correct?

    I think this might do what you need...
    // Create a dummy XML document
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputStream bais = new ByteArrayInputStream("<test><e1/></test>".getBytes());       
    Document doc = db.parse(bais);
    // Define the XPath expression to "select" the parent element in the document       
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression xpathExpression = xpath.compile("/test/e1");    
    // Select the parent node (should probably chuck an ex if not present)       
    Node node = (Node) xpathExpression.evaluate(doc, XPathConstants.NODE);
    // Create and append the child element
    node.appendChild(doc.createElement("newElement"));
    // Convert the Document into a string
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(baos);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(source, result);
    // <?xml version="1.0" encoding="UTF-8"?><test><e1><newElement/></e1></test>
    System.out.println(baos.toString());

  • Using XPATH to extract value.

    I need some help to extract the LatestFillQuantity element value using XPATH.
    in Java.
    I am unable to extract the value of 10000.
    Please help as to what have I done wrong.?
    The Document configNode contains the flwg:
    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <i:Interest >
         <i:Generation>3</i:Generation>
         <i:Extension>
            <i:Active.From/>
            <i:Order>
              <i:Status>Confirm</i:Status>
              <i:LatestFillQuantity>100</i:LatestFillQuantity>
            </i:Order>
    </i:Extension>
    </i:Interest>
    My Java Code
    private void extractValue(Document configNode)
         XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
              try{
             XPathExpression expr
              = xpath.compile("//i:Order/i:LatestFillQuantity/text()");
             Object result = expr.evaluate(configNode, XPathConstants.NODESET);
             NodeList nodes = (NodeList) result;
             for (int i = 0; i < nodes.getLength(); i++) {
                 System.out.println(nodes.item(i).getNodeValue());
             }catch(Exception e){
                  System.out.println("Sorry,this aint working");
         }

    The nodes being parsed are namespace prefixed.
    To parse a namespace node with the JDK 5.0 javax.xml.xpath package, set the NamespaceContext on the XPath object.
    An implementation of NamespaceContext with a single prefix corresponding to a namespace uri:
    public class NamespaceContextImpl implements NamespaceContext{
    public String uri;
    public String prefix;
    public NamespaceContextImpl(){}
    public NamespaceContextImpl(String prefix, String uri){
         this.uri=uri;
         this.prefix=prefix;
    public String getNamespaceURI(String prefix){
       return uri;
    public void setNamespaceURI(String uri){
       this.uri=uri;
    public String getPrefix(String uri){
       return prefix;
    public void setPrefix(String prefix){
       this.prefix=prefix;
    public Iterator getPrefixes(String uri){return null;}
    }

  • Copying Variables in BPEL using XPath Query

    Hi,
    I am new to BPEL and i want to know if it is possible to copy data from one variable to another using XPath Query in the <from> <to> tags, when the two variables are of different message types.
    I am trying to create a sample BPEL that would receive a String through the receive tag tied to one partner link (WSDl) and then invoke a different webservice using the <invoke> tag tied to another partner link (WSDL) by passing the received variable.
    I have pasted the BPEL File and the two WSDl files involved.
    My Issue is that when I send a soap request to the BPEL, it is passed as null to the webservice invoked.
    Probably because the copy tags don't work.
    Please help.
    BPEL File
    <!--
    ~ Licensed to the Apache Software Foundation (ASF) under one
    ~ or more contributor license agreements. See the NOTICE file
    ~ distributed with this work for additional information
    ~ regarding copyright ownership. The ASF licenses this file
    ~ to you under the Apache License, Version 2.0 (the
    ~ "License"); you may not use this file except in compliance
    ~ with the License. You may obtain a copy of the License at
    ~
    ~ http://www.apache.org/licenses/LICENSE-2.0
    ~
    ~ Unless required by applicable law or agreed to in writing,
    ~ software distributed under the License is distributed on an
    ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    ~ KIND, either express or implied. See the License for the
    ~ specific language governing permissions and limitations
    ~ under the License.
    -->
    <process name="HelloWorld2"
    targetNamespace="http://ode/bpel/unit-test"
    xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
    xmlns:tns="http://ode/bpel/unit-test"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:test="http://ode/bpel/unit-test.wsdl"
    xmlns:ns0="http://poc.com"
    queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
    expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0">
    <import location="HelloWorld2.wsdl"
    namespace="http://ode/bpel/unit-test.wsdl"
    importType="http://schemas.xmlsoap.org/wsdl/" />
    <import location="sayHello.wsdl"
    namespace="http://poc.com"
    importType="http://schemas.xmlsoap.org/wsdl/" />
    <partnerLinks>
    <partnerLink name="helloPartnerLink"
    partnerLinkType="test:HelloPartnerLinkType"
    myRole="me" />
    <partnerLink name="sayHelloBPELPL"
    partnerLinkType="ns0:sayHelloPLT"
    partnerRole="you" initializePartnerRole="yes" />
    </partnerLinks>
    <variables>
    <variable name="myVar" messageType="test:HelloMessage"/>
    <variable name="tmpVar" messageType="test:HelloMessage"/>
    <variable name="inVar" messageType="ns0:sayHelloRequest"/>
    <variable name="outVar" messageType="ns0:sayHelloResponse"/>
    </variables>
    <sequence>
    <receive
    name="start"
    partnerLink="helloPartnerLink"
    portType="test:HelloPortType"
    operation="hello"
    variable="myVar"
    createInstance="yes"/>
    <assign name="ass1">
    <copy>
    <from variable = "myVar" part = "TestPart"/>
    <to variable = "inVar"
    part = "parameters"
    query= "/sayHello/ns0:param0" />
    </copy>
    </assign>
    <invoke partnerLink = "sayHelloBPELPL"
    portType = "ns0:sayHelloPortType"
    inputVariable = "inVar"
    operation = "sayHello"
    outputVariable = "outVar">
    </invoke>
    <assign name="ass2">
    <copy>
    <from variable = "outVar"
    part = "parameters"
    query= "/sayHelloResponse/ns0:return" />
    <to variable = "tmpVar" part="TestPart"/>
    </copy>
    </assign>
    <reply name="end"
    partnerLink="helloPartnerLink"
    portType="test:HelloPortType"
    operation="hello"
    variable="tmpVar"/>
    </sequence>
    </process>
    WSDL File1
    <?xml version="1.0" encoding="utf-8" ?>
    <!--
    ~ Licensed to the Apache Software Foundation (ASF) under one
    ~ or more contributor license agreements. See the NOTICE file
    ~ distributed with this work for additional information
    ~ regarding copyright ownership. The ASF licenses this file
    ~ to you under the Apache License, Version 2.0 (the
    ~ "License"); you may not use this file except in compliance
    ~ with the License. You may obtain a copy of the License at
    ~
    ~ http://www.apache.org/licenses/LICENSE-2.0
    ~
    ~ Unless required by applicable law or agreed to in writing,
    ~ software distributed under the License is distributed on an
    ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    ~ KIND, either express or implied. See the License for the
    ~ specific language governing permissions and limitations
    ~ under the License.
    -->
    <wsdl:definitions
    targetNamespace="http://ode/bpel/unit-test.wsdl"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="http://ode/bpel/unit-test.wsdl"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"
    xmlns:ns0="http://poc.com">
    <wsdl:message name="HelloMessage">
    <wsdl:part name="TestPart" type="xsd:string"/>
    </wsdl:message>
    <wsdl:portType name="HelloPortType">
    <wsdl:operation name="hello">
    <wsdl:input message="tns:HelloMessage" name="TestIn"/>
    <wsdl:output message="tns:HelloMessage" name="TestOut"/>
    </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="HelloSoapBinding" type="tns:HelloPortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="hello">
    <soap:operation soapAction="" style="rpc"/>
    <wsdl:input>
    <soap:body
    namespace="http://ode/bpel/unit-test.wsdl"
    use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body
    namespace="http://ode/bpel/unit-test.wsdl"
    use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="HelloService">
    <wsdl:port name="HelloPort" binding="tns:HelloSoapBinding">
    <soap:address location="http://localhost:8082/ode/processes/helloWorld"/>
    </wsdl:port>
    </wsdl:service>
    <plnk:partnerLinkType name="HelloPartnerLinkType">
    <plnk:role name="me" portType="tns:HelloPortType"/>
    <plnk:role name="you" portType="tns:HelloPortType"/>
    </plnk:partnerLinkType>
    </wsdl:definitions>
    WSDL File 2
    <?xml version="1.0" encoding="UTF-8" ?>
    <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:ns0="http://poc.com"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:ns1="http://org.apache.axis2/xsd"
    xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"
    targetNamespace="http://poc.com">
    <wsdl:types>
    <xs:schema xmlns:ns="http://poc.com" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://poc.com">
    <xs:element name="sayHello">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" name="param0" nillable="true" type="xs:string" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="sayHelloResponse">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" name="return" nillable="true" type="xs:string" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    </wsdl:types>
    <wsdl:message name="sayHelloRequest">
    <wsdl:part name="parameters" element="ns0:sayHello" />
    </wsdl:message>
    <wsdl:message name="sayHelloResponse">
    <wsdl:part name="parameters" element="ns0:sayHelloResponse" />
    </wsdl:message>
    <wsdl:portType name="sayHelloPortType">
    <wsdl:operation name="sayHello">
    <wsdl:input message="ns0:sayHelloRequest" wsaw:Action="urn:sayHello" />
    <wsdl:output message="ns0:sayHelloResponse" wsaw:Action="urn:sayHelloResponse" />
    </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="sayHelloSOAP11Binding" type="ns0:sayHelloPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="sayHello">
    <soap:operation soapAction="urn:sayHello" style="document"/>
    <wsdl:input>
    <soap:body use="literal" />
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal" />
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="sayHello">
    <wsdl:port name="sayHelloPort" binding="ns0:sayHelloSOAP11Binding">
    <soap:address location="http://localhost:8082/ode/processes/sayHello" />
    </wsdl:port>
    </wsdl:service>
    <plnk:partnerLinkType name="sayHelloPLT">
    <plnk:role name="me" portType="ns0:sayHelloPortType"/>
    <plnk:role name="you" portType="ns0:sayHelloPortType"/>
    </plnk:partnerLinkType>
    </wsdl:definitions>

    Hi,
    Yes, it very much is possible.
    Xpath query provides a lot many data type conversion functions(string to int, string to date etc), which can be used in copying variables.
    thanks
    Saurabh

  • How to extract node value by using xpath in orchestration shape

    i want extract the node value by using xpath in expression shape in orch, then assign to variable.
    then decide shape in if branch im using check condition based nodevalue .
    str = xpath(Message_3, ("string(/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_ProjectRNd2.Schema3']/*[local-name()='no' and namespace-uri()=''])"));
    but i got below error:
    xlang/s engine event log entry: Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'BizTalk_Server_ProjectRNd2.BizTalk_Orchestration1(f3c581d3-049f-8a8a-9316-fc1235b03f99)'.
    The service instance will remain suspended until administratively resumed or terminated. 
    If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
    InstanceId: 020779be-713d-408c-9ff4-fd1462c2e52c
    Shape name: Expression_1
    ShapeId: b865a3e1-7ebe-410d-9f60-8ad2139ad234
    Exception thrown from: segment 1, progress 10
    Inner exception: There is an error in the XML document.
    Exception type: InvalidOperationException
    Source: System.Xml
    Target Site: System.Object Deserialize(System.Xml.XmlReader, System.String, System.Xml.Serialization.XmlDeserializationEvents)
    The following is a stack trace that identifies the location where the exception occured
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
       at Microsoft.XLANGs.Core.Part.XPathLoad(Part sourcePart, String xpath, Type dstType)
       at BizTalk_Server_ProjectRNd2.BizTalk_Orchestration1.segment1(StopConditions stopOn)
       at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)
    Additional error information:
            <no xmlns=''> was not expected.
    Exception type: InvalidOperationException
    Source: System.Xml
    Target Site: System.Object Read_string()
    The following is a stack trace that identifies the location where the exception occured
       at System.Xml.Serialization.XmlSerializationPrimitiveReader.Read_string()
       at System.Xml.Serialization.XmlSerializer.DeserializePrimitive(XmlReader xmlReader, XmlDeserializationEvents events)
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

    Hi,
    as per your  code i got below error 
    Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'BizTalk_Server_ProjectRNd2.BizTalk_Orchestration1(f3c581d3-049f-8a8a-9316-fc1235b03f99)'.
    The service instance will remain suspended until administratively resumed or terminated. 
    If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
    InstanceId: f5fffb05-e6d6-4765-83da-4e6c9696dd8a
    Shape name: Expression_1
    ShapeId: b865a3e1-7ebe-410d-9f60-8ad2139ad234
    Exception thrown from: segment 1, progress 10
    Inner exception: There is an error in the XML document.
    Exception type: InvalidOperationException
    Source: System.Xml
    Target Site: System.Object Deserialize(System.Xml.XmlReader, System.String, System.Xml.Serialization.XmlDeserializationEvents)
    The following is a stack trace that identifies the location where the exception occured
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializat
    this is my schema:
      <?xml version="1.0" encoding="utf-16"
    ?>
    <xs:schema xmlns="http://BizTalk_Server_ProjectRNd2.Schema3" xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
    xmlns:ns0="https://BizTalk_Server_ProjectRNd2.PropertySchema" targetNamespace="http://BizTalk_Server_ProjectRNd2.Schema3" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:annotation>
    <xs:appinfo>
    <b:imports>
      <b:namespace
    prefix="ns0" uri="https://BizTalk_Server_ProjectRNd2.PropertySchema" location=".\PropertySchema.xsd"
    />
      </b:imports>
      </xs:appinfo>
      </xs:annotation>
    <xs:element name="Root">
    <xs:annotation>
    <xs:appinfo>
    <b:properties>
      <b:property
    name="ns0:no" xpath="/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_ProjectRNd2.Schema3']/*[local-name()='no' and namespace-uri()='']"
    />
      </b:properties>
      </xs:appinfo>
      </xs:annotation>
    <xs:complexType>
    <xs:sequence>
      <xs:element
    name="no" type="xs:string" />
      <xs:element
    name="name" type="xs:string" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:schema>

  • Xslt copy-of creates a xml which returns empty while trying to access elements using XPATH

    Hi
    I am trying to do a copy-of function using the XSLT in jdev. This is what I do
        <xsl:param name="appdataDO"/>
        <xsl:template match="/">
        <ns1:applicationData>
          <ns1:applicationId>
            <xsl:value-of select="$appdataDO/ns1:applicationData/ns1:applicationId"/>
          </ns1:applicationId>
          <xsl:copy-of select="/fslo:ExternalapplicationData/fslo:ApplicationsHDRAddInfo">
          </xsl:copy-of>
        </ns1:applicationData>
        </xsl:template>
        </xsl:stylesheet>
    After this I can see the document created in the process flow as this :
        <ns1:applicationData>
        <ns1:applicationId>MMMM</ns1:applicationId>
        <ns2:ApplicationsHDRAddInfo>
        <ns3:genericFromBasePrimitive>iuoui</ns3:genericFromBasePrimitive>
        <ns4:EstimatedMarketValue>77</ns4:EstimatedMarketValue>
        <ns4:PropertyInsuranceFee>jih</ns4:PropertyInsuranceFee>
        <ns4:LoanOriginationFee>hjh</ns4:LoanOriginationFee>
        <ns4:RegistrarFee>kkkkk</ns4:RegistrarFee>
        <ns4:LoanCashInFee>hjh</ns4:LoanCashInFee>
        <ns4:LoanPaidInCashFlag>cddffgd</ns4:LoanPaidInCashFlag>
        </ns2:ApplicationsHDRAddInfo>
        </ns1:applicationData>
    But whenever I am trying to extract any of the output nodes I am getting an empty result. I can copy the whole dataset into similar kind of variable.
    But I am unable to get individual elements using XPATH.
    I tried using exslt function for node set and xslt 2.0 without avail.
    The namespaces might be the culprit here . The test method in the jdev is able to output a result but at runtime the xpath returns empty .
    I have created another transform where I try to copy data from the precious dataobject to a simple string in another data object .
    This is the test sample source xml for the transform created by jdev while testing with all namespaces, where I try to copy the data in a simple string in another data object.
        <applicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/bpmpa/fs/ulo/types file:/C:/JDeveloper/NewAPP/Xfrm/xsd/ApplicationData.xsd" xmlns="http://xmlns.oracle.com/bpmpa/fs/ulo/types">
           <applicationId>applicationId289</applicationId>
           <ApplicationsHDRAddInfo>
              <genericFromBasePrimitive xmlns="http://xmlns.oracle.com/bpm/pa/extn/types/BasePrimitive">genericFromBasePrimitive290</genericFromBasePrimitive>
              <EstimatedMarketValue xmlns="http://xmlns.oracle.com/bpm/pa/extn/headerCategories/">291</EstimatedMarketValue>
              <PropertyInsuranceFee xmlns="http://xmlns.oracle.com/bpm/pa/extn/headerCategories/">PropertyInsuranceFee292</PropertyInsuranceFee>
              <LoanOriginationFee xmlns="http://xmlns.oracle.com/bpm/pa/extn/headerCategories/">LoanOriginationFee293</LoanOriginationFee>
              <RegistrarFee xmlns="http://xmlns.oracle.com/bpm/pa/extn/headerCategories/">RegistrarFee294</RegistrarFee>
              <LoanCashInFee xmlns="http://xmlns.oracle.com/bpm/pa/extn/headerCategories/">LoanCashInFee295</LoanCashInFee>
              <LoanPaidInCashFlag xmlns="http://xmlns.oracle.com/bpm/pa/extn/headerCategories/">LoanPaidInCashFlag296</LoanPaidInCashFlag>
           </ApplicationsHDRAddInfo>
        </applicationData>
    And the xslt
        <xsl:template match="/">
            <ns1:DefaultOutput>
              <ns1:attribute1>
                <xsl:value-of select="/fslo:applicationData/fslo:ApplicationsHDRAddInfo/custom:LoanOriginationFee"/>
              </ns1:attribute1>
            </ns1:DefaultOutput>
          </xsl:template>
    This results in a empty attribute1. Any help will be appreciated .

    Please delete attributeFormDefault="qualified" elementFormDefault="qualified" from your XSD
    Please check the next link:
    http://www.oraclefromguatemala.com.gt/?p=34

  • How to use XPath in the adapter framework

    I am creating a XI adapter to our system.
    In the adapter I want to use XPath expression.
    I use the classes from javax.xml.xpath.*
    This way does not work in the XI application server. (Java 1.4.2)
    What is the correct way? Which packages/classes must be used?
    Miklos

    Hi Miklos,
    The package javax.xml.xpath was introduced with Java 5 (1.5), thus it is not available in XI which runs Java 1.4.2. There are (at least) a couple of ways to use XPath in Java 1.4:
    1. Use a third-party library that supports XPath, for instance Xalan-J from Apache.
    2. Embed your XPath expression in an XSLT transformation, execute the transformation using classes from the javax.xml.tranform... packages (which <i>are</i> part 1.4) and extract the result.
    Cheers,
    Thorsten

  • Using Xpath in Receiver Determination for greater than 500

    Hi,
    I am trying to use Xpath in the receiver Determination step and I want to check a field which is at item level and comes multiple times(0-unbounded) greater than 500.I tried with different options per SDN blogs,Xpath functions,but still I couldn't able to get what i am trying.I want to process the message when "quantity" is greater than 500,else I want to ignore the message with no errors.
    I gave like this    /p1: /LIST/item[quantity>499]     EX
    item loop is 0-unbounded and I need to check for every quantity.I selected the check box multi line as well.
    I played around different options,but still did not get what I am looking for.
    please suggest in this regard ,how I need to give the expression.
    Thank you,
    Sri

    Hi,
    For validating that the item field is occuring more than 500 times you need to choose the
    2.The exact XPath would be in your case *(/p1: /LIST/itemquantity[499]EX)*
    This means if the 500 th occurance of the item exists then the condition satisfies that is always true for 500 and above occurance of the item.
    Please revert if the suggestion proves to be helpful.
    cheers,
    Abhishek.
    Edited by: Abhishek  Paul on May 6, 2010 10:55 PM
    Edited by: Abhishek  Paul on May 6, 2010 11:02 PM
    Edited by: Abhishek  Paul on May 6, 2010 11:08 PM

  • How to use XPath with Namespaces in the xml ?

    Hi all,
    I need to reference a certain Node in a Document using XPath notation.
    The problem is the the XML Document contains Namespaces inside it
    f.e.
    <xn:SubNetwork id="JRANM">
        <xn:VsDataContainer id="1">
           <xn:vsDataType>vsDataAreas</xn:vsDataType>
        </xn:VsDataContainer>
    </xn:SubNetwork >Using DOMXPath (from weblogic.xml.xpath)
      DOMXPath xPath = new DOMXPath("xn:SubNetwork/*");
      Set nodeset = xPath.evaluateAsNodeset(this.xmlRootElement);When I Iterate through the Set I can see it's empty.
    (On the other hand without namespaces everything is fine.)
    So how can I reference a Node that contains a namespace in it ?
    Thanks a lot
    Francesco

    We use the following class to perform XPath Queries on our XmlBean objects.
    Hope this helps,
    Craig
    import java.util.Set;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.apache.xmlbeans.XmlException;
    import org.w3c.dom.Document;
    import weblogic.xml.util.StringInputStream;
    import weblogic.xml.xpath.DOMXPath;
    * Class to encapsulate API specific (i.e. weblogic) XML functions
    public class XmlUtil {
         * Returns a set containing objects of type reflected in the query.<br/>
         * e.g.<br/>
         * /saur:tree/saur:treeNode[@label='My Reports']<br/>
         * Returns a Set of TreeNode objects<br/>
         * Sample Code: <br/>
         * <code>
         * Set set = XmlUtil.executeXPathQuery( myQuery, tree.xmlText());
         * for( Iterator iter = set.iterator(); iter.hasNext();) {
         *     TreeNode node = TreeNode.Factory.parse((Node)iter.next());
         *     // Do whatever...
         * </code>
         * @param query
         * @param xml
         * @return
        public static Set executeXPathSetQuery( String query, String xml) throws XmlException {
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();   
                factory.setNamespaceAware(true);
                DocumentBuilder builder = factory.newDocumentBuilder();
                StringInputStream in = new StringInputStream(xml);
                Document doc = builder.parse(in);
                DOMXPath xQuery =  new DOMXPath(query);
                return xQuery.evaluateAsNodeset(doc);
            catch(Exception x) {
                throw new XmlException("Error running XPath query", x);
    }

  • How do I retrive date field using Xpath

    How do I retrive data,which is in date format in XML file using XPath query.
    If this is not possible, Is there any other alternative?
    Bye

    Hi,
    If suppose my xml file is like this,
    <Xml>
    <DataSet>
         <BirthDate>1-Sep-1980</BirthDate>
         <BirthDate>6-Aug-1982</BirthDate>
         <BirthDate>3-Sep-1981</BirthDate>
         <BirthDate>12-Jan-1985</BirthDate>
         <BirthDate>1-Sep-1979</BirthDate>
    </DataSet>
    </Xml>
    If I want to retrive Data,BirthDate between 1-Jan-1981 and 1-Jan-1984
    How do I do that?
    If it is not possible directly,Is there any other alternative?
    Bye

  • Xml loading using xpath in pl/sql

    Hi,
    I am loading xml using xpath query bu i am stucked here.I am not able to pass the loop counter "I" into the query.Please help.
    The problem is in line " 13 FROM xml_table,table(XMLSequence(extract(OBJECT_VALUE, '/BIF/SBI/SBC/flag'))) li;
    " in the below block
    1 declare
    2 SBI_count pls_integer;
    3 begin
    4 select count(*)
    5 into SBI_count
    6 from xml_table,table(XMLSequence(extract(OBJECT_VALUE, '/BIF/SBI') ) );
    7 dbms_output.put_line( 'SBI_count '||SBI_count );
    8 for I in 1..SBI_count
    9 LOOP
    10 INSERT INTO Subclass_Date_Flags( Subclass_Id,
    11 subclass_date_flags_8 )
    12 SELECT 'SID',extractvalue(VALUE(li), '//flag')
    13 FROM xml_table,table(XMLSequence(extract(OBJECT_VALUE, '/BIF/SBI[I]/SBC/flag'))) li;
    14 dbms_output.put_line( 'Row '||SQL%ROWCOUNT );
    15 END LOOP;
    16 commit;
    17* end;
    SQL> /
    SBI_count 2
    Row 0
    Row 0
    PL/SQL procedure successfully completed.

    Try this code, just keep a reference to your root node so you can keep appending children to it:
    DECLARE
    xmlDoc xmldom.DOMDocument;
    xmlNode xmldom.DOMNode;
    xmlNode1 xmldom.DOMNode;
    xmlElem1 xmldom.DOMElement;
    xmlElem2 xmldom.DOMElement;
    xmlText xmldom.DOMText;
    CURSOR cur_emp IS
    SELECT *
    FROM emp;
    --WHERE empno = 7369;
    row_emp emp%ROWTYPE;
    BEGIN
    xmlDoc := xmldom.newDOMDocument;
    xmlNode := xmldom.makeNode(xmlDoc);
    xmlElem1 := xmldom.createElement(xmlDoc,'root');
    xmlNode := xmldom.appendChild(xmlNode,xmldom.makeNode(xmlElem1));
    OPEN cur_emp;
    LOOP
    FETCH cur_emp INTO row_emp;
    EXIT WHEN cur_emp%NOTFOUND;
    xmlElem2 := xmldom.createElement(xmlDoc,'name');
    xmldom.setAttribute(xmlElem2, 'empno',TO_CHAR(row_emp.empno));
    xmlNode1 := xmldom.appendChild(xmlNode,xmldom.makeNode(xmlElem2));
    xmlText := xmldom.createTextNode(xmlDoc,row_emp.ename);
    xmlNode1 := xmldom.appendChild(xmlNode1,xmldom.makeNode(xmlText));
    END LOOP;
    CLOSE cur_emp;
    xmldom.writeToFile(xmlDoc,'c:\xmltest1.txt');
    END;
    null

  • Count multiple nodes in XML using xPath

    Hi',
    How to count the CUSTSERIAL node in the below XML using xPath.
    <missingICCRec>
    <MissingField xmlns="http://www.Google.com/MissingFields/v1.0">
    <CUSTSERIAL xmlns="http://Google.com/InboundService">23809002RN</CUSTSERIAL>
    <CUSTSERIAL xmlns="http://Google.com/InboundService">23809003RN</CUSTSERIAL>
    <CUSTSERIAL xmlns="http://Google.com/InboundService">23809004RN</CUSTSERIAL>
    </MissingField>
    </missingICCRec>
    Thanks
    Yatan

    Yatan,
    I created a simple BPEL with assign to count the node. Using ora:countNodes() function is throwing exception but when i tried with count() it works.
    XSD seems to be valid. Only you need to have the function as below.
    count(bpws:getVariableData('inputVariable','payload','/client:process/client:missingICCRec/client:MissingField/client:CUSTSERIAL'))
    XSD Used:
    <?xml version="1.0" encoding="UTF-8"?>
    <schema attributeFormDefault="unqualified" elementFormDefault="qualified"
    targetNamespace="http://xmlns.oracle.com/PIMtoRPASAmendment/BPLENodeCount/BPLENodeCount"
    xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="process">
    <complexType>
    <sequence>
    <element name="missingICCRec">
    <complexType>
    <sequence>
    <element name="MissingField">
    <complexType>
    <sequence>
    <element name="CUSTSERIAL" maxOccurs="unbounded" type="string"/>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </element>
    <element name="processResponse">
    <complexType>
    <sequence>
    <element name="result" type="string"/>
    </sequence>
    </complexType>
    </element>
    </schema>
    This works !!!
    Please let me know if this helps.
    Thanks,
    Vijay

Maybe you are looking for

  • How To Set Up Mountain Lion Server/Point DNS to Mac Mini Server

    Hello, First of all I have no experience with setting up servers whatsoever. Below is what I have - Mac Mini with Mountain Lion Server - Time Capsule as my router - Comcast as my service provider My goal is to set up my MacMini as a sharepoint for fi

  • Add functionalities to SAP Strategy Management

    Hello, I am a student who wants to add some functionalities to the SAP Strategy Management software, to make it more collaborative. I subscribed to this very collaborative SAP website to find an answer on two questions: - is it possible for me as an

  • Error while writing a rotuine!! Help me

    Hi Guys, Bleow is the code : "DATA: L_S_DATAPAK_LINE TYPE TRANSFER_STRUCTURE. LOOP AT DATAPAK INTO L_S_DATAPAK_LINE. IF L_S_DATAPAK_LINE-ITM_SC_H_OBJ_ID = '0010092184'.    L_S_DATAPAK_LINE-ITM_DESCRIPTION  = 'PT/UIOPLANTRONICS U1OP'.    modify DATAPA

  • Changing PR Document Type

    Dear Experts, Just want to know whether there is a way to raise PR through a project with a customize PR document type (except the standard NB type). Your guidance is well appreciated. Regards, Dileepa.

  • IBooks is using "Sort Name" and not "Name". How do I fix this?

    I need help. I have sorted through all my ebooks, changing them to epub, editing metadata to have correct title, author, and even series (title and order) using a program called Calibre. When I sent these to my iTunes-iBooks it chooses to sort them b