Announcement Announcement Module
Collapse
No announcement yet.
Problems with xPathtemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with xPathtemplate

    Hi,

    I use the WebServiceTemplate of Arjen's Spring-WS and receive the following xml-file as a response to my request.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
    	xmlns:ns0="http://exception.core.jabba.ptvag.com"
    	xmlns:ns1="http://common.xserver.ptvag.com"
    	xmlns:ns2="http://xlocate.xserver.ptvag.com"
    	xmlns:ns3="http://types.xlocate.xserver.ptvag.com">
    	<env:Body>
    		<ns3:matchAddressResponse>
    			<ns3:result>
    				<ns2:ResultAddress xsi:type="ns2:ResultAddress"
    					city="Oberrod" city2="" country="D" houseNumber="" postCode="56479"
    					state="" street="" adminRegion="Oberrod" appendix=""
    					classificationDescription="UNIQUE" countryCapital="Berlin"
    					detailLevelDescription="CITY" totalScore="100">
    					<ns2:wrappedAdditionalFields />
    					<ns2:coordinates xsi:type="ns1:Point">
    						<ns1:point xsi:type="ns1:PlainPoint"
    							x="812654.9999999993" y="5058570.0" />
    					</ns2:coordinates>
    				</ns2:ResultAddress>
    				<ns2:ResultAddress xsi:type="ns2:ResultAddress"
    					city="Ebersburg" city2="Oberrod" country="D" houseNumber=""
    					postCode="36157" state="" street="" adminRegion="Ebersburg"
    					appendix="" classificationDescription="HIGH"
    					countryCapital="Berlin" detailLevelDescription="CITY2"
    					totalScore="100">
    					<ns2:wrappedAdditionalFields />
    					<ns2:coordinates xsi:type="ns1:Point">
    						<ns1:point xsi:type="ns1:PlainPoint"
    							x="983543.9999999995" y="5046744.0" />
    					</ns2:coordinates>
                               </ns2:ResultAddress>
    			</ns3:result>
    		</ns3:matchAddressResponse>
    	</env:Body>
    </env:Envelope>
    After receiving this I try to extract the values of all attributes in the <ns2:ResultAddress> Elements and the x and y attribute in the <ns1oint> Elements

    I use the Jaxp13XPathTemplate to extract the information I need out of the response (xPathTemplate.evaluatesAsString(expression, response)) but cannot find the correct XPath-Expression that leads me to the values of these attributes ...

    I'd appreciate if someone could help or give me some hints to find the corresponding xPath-expression

    johannes

  • #2
    W3Schools has an excellent tutorial for XPath: http://www.w3schools.com/xpath/xpath_syntax.asp.

    For all the attributes in ResultAddress, you can use
    Code:
    /ns3:matchAddressResponse/ns3:result/ns2:ResultAddress/@*
    For the x attribute:
    Code:
    /ns3:matchAddressResponse/ns3:result/ns2:ResultAddress/ns2:coordinates/ns1:point/@x
    And for y:
    Code:
    /ns3:matchAddressResponse/ns3:result/ns2:ResultAddress/ns2:coordinates/ns1:point/@y
    Evaluating these to Strings won't do you any good, though, since there are multiple results. So you have to use evaluateAsNodeList, which will return a list of org.w3c.dom.Attrs, or better yet: use the NodeMapper to create objects from the Attrs.

    Comment

    Working...
    X