DOM4J/XPATH Parsing of document
Node existingUserNode = loginDoc.selectSingleNode("/returningUser");
String username = existingUserNode.selectSingleNode("/username").getText();
String password = existingUserNode.selectSingleNode("/password").getText();
for
<?xml version="1.0" enc开发者_开发知识库oding="UTF-8"?><returningUser><username>user</username><password>password</password></returningUser>
returns null.
I don't think my xpath is wrong? Or am I using the wrong method?
The syntax should be ./username and ./password... above I am looking one level too high by referencing the root
try this
Node existingUserNode = loginDoc.selectSingleNode("/returningUser");
String username = existingUserNode.selectSingleNode("/username").getNodeValue();
String password = existingUserNode.selectSingleNode("/password").getNodeValue();
精彩评论