Hi,
If I have the following XML:
<ib type="set" from="vas" id="2301181" to="DEV_LG"
xmlns="
http://www.vettro.com/1/ib.xsd">
<service username="leegardner">
<vas:update xmlns:vas="
http://www.vettro.com/1/vas.xsd">
<vas:field name="serial">ABC</vas:field>
</vas:object>
</vas:update>
</service>
</ib>
Would the following XPath extract the text node holding ABC:
/service/vas:update/vas:object/vas:field[@name='serial']/text()
Assuming the namespaces were declared:
vas ->
http://www.vettro.com/1/ib.xsdCode sample:
xpf = XPathFactory.newInstance();
xpath = xpf.newXPath();
xpath.setNamespaceContext(new MyNamespaceContext());
XPathExpression e = xpath.compile(expression);
Object o = e.evaluate(target, XPathConstants.NODESET);
protected class MyNamespaceContext implements NamespaceContext
{
private Map namespaceMap = new HashMap();
public void addNamespace(String prefix, String url)
{ namespaceMap.put(prefix, url); }
public void addNamespaces(Map map)
{ namespaceMap.putAll(map); }
public String getNamespaceURI(String prefix)
{
String s = (String)namespaceMap.get(prefix);
if (s == null) s = "";
return s;
}
public String getPrefix(String uri)
{ return null; }
public Iterator getPrefixes(String namespaceURI)
{ return null; }
}
(Interestingly, Saxon never calls the namespace context implementation.)
Thanks,
John
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
saxon-help mailing list archived at
http://saxon.markmail.org/saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help