Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > how to specify namespace in saxon api ??

Thread Tools

how to specify namespace in saxon api ??

Posts: n/a
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 :

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.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
//expression = "//g[@id='textes_x0020_et_x0020_puces']/g/text";
// Compile the XPath expressions used by the application
XPathExpression findLine = xpe

// 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);

// // Find where it appears in the play
// findLocation.setContextNode(line);
// System.out.println("\n" +
// // 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 "."


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Use XML attributes to specify another XML name or namespace... Web Developer ASP .Net Web Services 0 02-17-2005 09:01 PM
How to force use of SAXON xslt processor? Collin VanDyck Java 1 04-02-2004 09:34 PM
Anything faster than Saxon with similiar features? ted XML 1 02-16-2004 05:43 AM
saxon document() location Johannes Busse XML 1 07-01-2003 01:54 PM
saxon document() location Johannes Busse XML 0 06-30-2003 02:28 PM