I have read several threads on the subject, this one being the closest to what I need, it seems simple, but it just doesn't work.
When I have the next xml:
<Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<Header>
<context xmlns="urn:zimbra"><change token="11127"/>
</context>
</Header>
<Body>
<Fault>
<Code>
<Value>Sender</Value>
</Code>
<Reason>
<Text>no such account: prueba5@empresarias.mx</Text>
</Reason>
<Detail>
<Error xmlns="urn:zimbra">
<Code>account.NO_SUCH_ACCOUNT</Code>
<Trace>qtp1027591600-66260:1597793723503:4b07a03bafc0cc32</Trace>
</Error>
</Detail>
</Fault>
</Body>
</Envelope>
I can easily get what I need, in my case I need the text in Reason, Text, which I get with:
Object fault =
xPath
.compile("/Envelope/Body/Fault/Reason/Text/text()")
.evaluate(xml, XPathConstants.STRING);
fault value is "no such account: prueba5@empresarias.mx", easy, right?
But when I have the next xml:
<Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<Header>
<context xmlns="urn:zimbra">
<change token="11127"/>
</context>
</Header>
<Body>
<GetAccountResponse xmlns="urn:zimbraAdmin">
<account name="prueba2@empresarias.mx" id="6819863b-fcf1-466f-b711-4310457274b3">
<a n="zimbraPasswordMustChange">TRUE</a>
<a n="zimbraId">6819863b-fcf1-466f-b711-4310457274b3</a>
</account>
</GetAccountResponse>
</Body>
</Envelope>
I'm trying to get the value of the attribute "id" inside "account", which I would think (based on other answers), that I would get with the next path:
Object zimbraId =
xPath2
.compile("/Envelope/Body/GetAccountResponse/account/@id")
.evaluate(xml2, XPathConstants.STRING);
I have tried several things, like getting the using the attribute "name" to search for it, like this:
Object zimbraId =
xPath2
.compile("/Envelope/Body/GetAccountResponse/account[@name='prueba2@empresarias.mx']/@id")
.evaluate(xml2, XPathConstants.STRING);
And many other things, but zimbraId is always "", I didn't want to post this question, but I'm really frustated.
Also, this is how zimbra service responds, so I can't change the xml. I'm suspicious about the "GetAccountResponse" element, but I don't really know what I'm doing wrong.
Any help would be very much appreciated.