how to specify namespace in saxon api ??

G

Gabriel

Greetings, After 6 hours of fruitless research, I ask for your help !

I have an svg file and use Saxon latest implementation, openSource version.

it holds nodes whose path are :
svg/g[@id='textes_x0020_et_x0020_puces']/g/text

each text node possess a transform attribute that I want to work with.

The problem is that whatever xPath expression I use, I never fetch any
nodes. According to the samples, it works with regular xml but doesn't
with svg (which is xml !). But well, it just doesn't :(
I tried to get svg width attributes as well but nope

After a lot of research it happenedn that sxon does not know about the
svg namespace. How can I tell him to be aware of it ??


Any ideas ?
The code :

import net.sf.saxon.xpath.XPathEvaluator;
import net.sf.saxon.xpath.XPathExpression;
import net.sf.saxon.xpath.StandaloneContext;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.xpath.Variable;
import org.xml.sax.InputSource;
import javax.xml.transform.sax.SAXSource;

import java.util.List;
import java.util.Iterator;

public void go(String filename) throws Exception {

// Create an XPathEvaluator and set the source document

InputSource is = new InputSource(filename);
SAXSource ss = new SAXSource(is);
XPathEvaluator xpe = new XPathEvaluator(ss);

StandaloneContext sc = (StandaloneContext) xpe.getStaticContext();
String expression = "//LINE[contains(., $word)]";

Variable wordVar = sc.declareVariable("word", "");
// Set the value of the XPath variable
wordVar.setValue("svg");
//expression = "//g[@id='textes_x0020_et_x0020_puces']/g/text";
// Compile the XPath expressions used by the application
XPathExpression findLine = xpe
.createExpression(expression);

// Find the lines containing the requested word
List matchedLines = findLine.evaluate();

// Process these lines
for (Iterator iter = matchedLines.iterator(); iter.hasNext();) {

// Get the next matching line
NodeInfo line = (NodeInfo) iter.next();

// // Find where it appears in the play
// findLocation.setContextNode(line);
// System.out.println("\n" +
findLocation.evaluateSingle());
//
// // Find out who the speaker of
this line is
// findSpeaker.setContextNode(line);

// Output the name of the speaker and the content of the
// line
// System.out.println(findSpeaker.evaluateSingle() + ": "
// + line.getStringValue());
// Finish when the user enters "."

}
System.out.println("Finished.");

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top