开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜