Reputation: 752
While playing around with JOOX I seem to struggle with the concept of actually getting some values from elements.
Consider the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<gwm:getAddressBookListResponse xmlns:gwm="http://schemas.novell.com/2005/01/GroupWise/methods" xmlns:gwt="http://schemas.novell.com/2005/01/GroupWise/types" xmlns:gwe="http://schemas.novell.com/2005/01/GroupWise/events">
<gwm:books>
<gwt:book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="gwt:AddressBook">
<gwt:id>584FB626.hbo.abp_poa1.104.16E3363.1.1.1@53</gwt:id>
<gwt:sid>1</gwt:sid>
<gwt:name>Contacts1</gwt:name>
<gwt:version>3</gwt:version>
<gwt:modified>2016-12-13T07:49:42Z</gwt:modified>
<gwt:isPersonal>1</gwt:isPersonal>
<gwt:isFrequentContacts>1</gwt:isFrequentContacts>
</gwt:book>
<gwt:book>
<gwt:id>GroupWiseSystemAddressBook@52</gwt:id>
<gwt:name>Contacts2</gwt:name>
<gwt:isPersonal>0</gwt:isPersonal>
<gwt:isFrequentContacts>0</gwt:isFrequentContacts>
</gwt:book>
<gwt:book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="gwt:AddressBook">
<gwt:id>584FB626.hbo.haporo_poa1.104.16E3363.1.3.1@53</gwt:id>
<gwt:sid>3</gwt:sid>
<gwt:name>Contacts3</gwt:name>
<gwt:version>3</gwt:version>
<gwt:modified>2016-12-13T07:49:42Z</gwt:modified>
<gwt:isPersonal>1</gwt:isPersonal>
<gwt:isFrequentContacts>0</gwt:isFrequentContacts>
</gwt:book>
<gwt:book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="gwt:AddressBook">
<gwt:id>584FB629.hbo.haporo_poa1.104.16E3363.1.5.1@53</gwt:id>
<gwt:sid>5</gwt:sid>
<gwt:name>Contacts4</gwt:name>
<gwt:version>2</gwt:version>
<gwt:modified>2016-12-13T07:49:45Z</gwt:modified>
<gwt:description>Bazinga !</gwt:description>
<gwt:isPersonal>1</gwt:isPersonal>
<gwt:isFrequentContacts>0</gwt:isFrequentContacts>
</gwt:book>
</gwm:books>
<gwm:status>
<gwt:code>0</gwt:code>
</gwm:status>
</gwm:getAddressBookListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I am interested in the gwt:id elements, or rather their values. Hence:
$(document).find("book").find("id").forEach(element -> {
element... // now what?
});
There is no such thing as element.getValue() and a toString() won't do as it prints aut the element name and value, though I am only interested in the value. Further, getNodeValue() returns null
How to get the value of the element I am after (e.g. 584FB629.hbo.haporo_poa1.104.16E3363.1.5.1@53)
Upvotes: 0
Views: 303
Reputation: 13063
The Element
class implements Node
interface, so you can use getTextContent()
.
Remember that in XML, the text contained within any element (tag) is also a node itself. Hence, Element
does not really have such thing as "text", only (possibly) descendant text node(s).
Upvotes: 1