Robert Chan
11-26-2009, 08:52 PM
Dear all,
I have this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<profiles>
<group name="CUS1">
<displayName>1024</displayName>
<groupID>1</groupID>
</group>
<group name="CUS2">
<displayName>1025</displayName>
<groupID>2</groupID>
</group>
<group name="CUS3">
<displayName>1026</displayName>
<groupID>3</groupID>
</group>
</profiles>
I am trying to locate some elements (a group with attribute name='CUS2') with JDOM and XPath with the following code:
...
import org.jdom.xpath.XPath;
...
profileElement = doc.getRootElement();
...
groupElement = (Element) XPath.selectSingleNode(profileElement, "//@'CUS2'");
.........
This causes exception (XPath evaluation failed). I also tried the following XPaths:
groupElement = (Element) XPath.selectSingleNode(profileElement, "/profiles/group[@name='CUS2']");
groupElement = (Element) XPath.selectSingleNode(profileElement, "//group[@name='CUS2']");
groupElement = (Element) XPath.selectSingleNode(profileElement, "//@\"CUS2\"");
They all failed. Can you spot what I have done wrong?
Thanks very much in advance.
Regards,
Robert.
I have this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<profiles>
<group name="CUS1">
<displayName>1024</displayName>
<groupID>1</groupID>
</group>
<group name="CUS2">
<displayName>1025</displayName>
<groupID>2</groupID>
</group>
<group name="CUS3">
<displayName>1026</displayName>
<groupID>3</groupID>
</group>
</profiles>
I am trying to locate some elements (a group with attribute name='CUS2') with JDOM and XPath with the following code:
...
import org.jdom.xpath.XPath;
...
profileElement = doc.getRootElement();
...
groupElement = (Element) XPath.selectSingleNode(profileElement, "//@'CUS2'");
.........
This causes exception (XPath evaluation failed). I also tried the following XPaths:
groupElement = (Element) XPath.selectSingleNode(profileElement, "/profiles/group[@name='CUS2']");
groupElement = (Element) XPath.selectSingleNode(profileElement, "//group[@name='CUS2']");
groupElement = (Element) XPath.selectSingleNode(profileElement, "//@\"CUS2\"");
They all failed. Can you spot what I have done wrong?
Thanks very much in advance.
Regards,
Robert.