how to specify namespace in saxon api ??

Discussion in 'XML' started by Gabriel, Oct 17, 2004.

  1. Gabriel

    Gabriel Guest

    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.");

    }
     
    Gabriel, Oct 17, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Collin VanDyck

    How to force use of SAXON xslt processor?

    Collin VanDyck, Apr 2, 2004, in forum: Java
    Replies:
    1
    Views:
    663
    Collin VanDyck
    Apr 2, 2004
  2. Johannes Busse

    saxon document() location

    Johannes Busse, Jun 30, 2003, in forum: XML
    Replies:
    1
    Views:
    996
    Johannes Busse
    Jul 1, 2003
  3. Johannes Busse

    saxon document() location

    Johannes Busse, Jun 30, 2003, in forum: XML
    Replies:
    0
    Views:
    1,021
    Johannes Busse
    Jun 30, 2003
  4. ted
    Replies:
    1
    Views:
    439
    Dimitre Novatchev [MVP XML]
    Feb 16, 2004
  5. Web Developer

    Use XML attributes to specify another XML name or namespace...

    Web Developer, Feb 17, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    810
    Web Developer
    Feb 17, 2005
Loading...

Share This Page