开发者

DOM4J/XPATH Parsing of document

开发者 https://www.devze.com 2023-01-10 17:10 出处:网络
Node existingUserNode = loginDoc.selectSingleNode(\"/returningUser\"); String username = existingUserNode.selectSingleNode(\"/username\").getText();
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

精彩评论

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