java - How to parse org.w3c.dom.Element RPX XML response -


I am using rpxnow in java, I have to get the field identifier org.w3c.dom API How do I use for example in this XML report?

  & lt ;? XML version = '1.0' encoding = 'UTF-8'? & Gt; & Lt; Rsp stat = 'OK' & gt; & Lt; Profile & gt; & Lt; DISPLAYNAME & gt; Brian & lt; / DisplayName & gt; & Lt; Identifier & gt; Http://brian.myopenid.com/ & lt; / Identifier & gt; & Lt; PreferredUsername & gt; Brian & lt; / Preferred username & gt; & Lt; ProviderName & gt; Other & lt; / Provider name & gt; & Lt; URL & gt; Http://brian.myopenid.com/ & lt; / Url & gt; & Lt; / Profile & gt; & Lt; / RSP & gt; Do you have a look at the API documentation of package  org w3c.dom <<> 
/ Code>? To achieve the child element with a specific tag name (and other methods that may be useful), such methods like getElementsByTagName (string name) are included in the class element . However, the use of this API is a bit complicated. You can see XPath (package javax.xml.xpath ) with a lower line of code. For example (untested):

  element element = ...; XPath xpath = XPathFactory.newInstance (). NewXPath (); Node node = (node) xpath.evaluate ("/ rsp [@ stat = 'OK'] / profile / identifier", element, XPathConstants.NODE); String value = node! = Null? Node.getTextContent (). Trim (): "";  

Comments