Problems with JDOm XPath

Hi all.
I have a JDOM XML document and I use JDOMXPath to apply XPath expressions on the XML document.
I have XPath expression for which JDOMXPath does not match any node:
//*[not(count(descendant::a) < 4)]
[not(descendant::node()[count(descendant::a)>3])]
[not(descendant::text()[normalize-space(string())!='']
[not(ancestor::a)])]
XML parser such as Saxon, MSXML, etc. correctly match this XPath on the document and find the appropriate node-set, so the XPath expression is 100% right from the XPath syntax perspective.
But in JDOM, it does not match.
Could anybody tell me what is the problem?
Thank you very much for help and sorry if this is the wrong place to ask this question - this is my first post here.
Thanks again,
Anna

Sorry, forgot to tell something very important:
the XML node-set that I am trying to match is as follows:
<ul>
<li>Accessibility</li>
<li>Amaya</li>
<li>ABC</li>
<li>CC/PP</li>
</ul>
The interesting moment is, that if I change the node-set to look like this:
<ul><li>Accessibility</li><li>Amaya</li><li>ABC</li><li><a href="Mobile/CCPP/"></a></li></ul>
i.e. without any spaces, JDOMXPath will match for the above XPath.
Is there any problem with spaces in JDOM/JDOMXPath?
Thanks again
Anna

Similar Messages

  • Intresting problem with JDOM and xmlns in root element.

    Hi all,
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element.Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
              <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
              <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
         </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("file location "));
         Element root = oDoc.getRootElement();
         System.out.println(root.getName());
         String tgtns= root.getAttributeValue("targetNamespace");
         System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
         Iterator it1= list.iterator();
         System.out.println(list.size());
         while(it1.hasNext()){
              Element partnerlinks = (Element)it1.next();
              List list2= partnerlinks.getChildren("partnerLink");
              System.out.println(list2.size());
              Iterator it2= list2.iterator();
              String[][] partnerLinkval = new String [2][list2.size()];
              int i=0,j=0;
              while(it2.hasNext())
                   Element el2= (Element)it2.next();
              String ElementName = el2.getName();
              partnerLinkval[i][j]= ElementName;
              j++;
              String Attribute = el2.getAttributeValue("myRole");
              partnerLinkval[i][j]= Attribute;
              i++;
              j--;
              System.out.println("Saving in array "+el2.getName());
              System.out.println("Saving in array "+Attribute);
              System.out.println("array length"+partnerLinkval.length);
              for (int l=0;l<2;l++){
              for(int k=0;k<partnerLinkval.length;k++)
                   System.out.println(partnerLinkval[l][k]);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file
    process
    tgt ns http://serena.com/buildserviceflow
    1
    2
    Saving in array partnerLink
    Saving in array BpelServiceFlowProvider
    Saving in array partnerLink
    Saving in array null
    array length2
    partnerLink
    BpelServiceFlowProvider
    partnerLink
    null
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    0

    Hi,
    I am also having the same problem using jdom, my code works fine when there is no xmlns attribute but when i put the xmlns attribute back in doesn't work.
    Did you manage to find a way to solve this problem?

  • How to parse XML document with default namespace with JDOM XPath

    Hi All,
    I am having difficulty parsing using Saxon and TagSoup parser on a namespace html document. The relevant content of this document are as follows:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <div id="container">
            <div id="content">
                <table class="sresults">
                    <tr>
                        <td>
                            <a href="http://www.abc.com/areas" title="Hollywood, CA">hollywood</a>
                        </td>
                        <td>
                            <a href="http://www.abc.com/areas" title="San Jose, CA">san jose</a>
                        </td>
                        <td>
                            <a href="http://www.abc.com/areas" title="San Francisco, CA">san francisco</a>
                        </td>
                        <td>
                            <a href="http://www.abc.com/areas" title="San Diego, CA">San diego</a>
                        </td>
                  </tr>
    </body>
    </html>
    Below is the relevant code snippets illustrates how I have attempted to retrieve the contents (value of  <a>):
                 import java.util.*;
                 import org.jdom.*;
                 import org.jdom.xpath.*;
                 import org.saxpath.*;
                 import org.ccil.cowan.tagsoup.Parser;
    ( 1 )       frInHtml = new FileReader("C:\\Tmp\\ABC.html");
    ( 2 )       brInHtml = new BufferedReader(frInHtml);
    ( 3 ) //    SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
    ( 4 )       SAXBuilder saxBuilder = new SAXBuilder("org.ccil.cowan.tagsoup.Parser");
    ( 5 )       org.jdom.Document jdomDocument = saxbuilder.build(brInHtml);
    ( 6 )       XPath xpath =  XPath.newInstance("/ns:html/ns:body/ns:div[@id='container']/ns:div[@id='content']/ns:table[@class='sresults']/ns:tr/ns:td/ns:a");
    ( 7 )       xpath.addNamespace("ns", "http://www.w3.org/1999/xhtml");
    ( 8 )       java.util.List list = (java.util.List) (xpath.selectNodes(jdomDocument));
    ( 9 )       Iterator iterator = list.iterator();
    ( 10 )     while (iterator.hasNext())
    ( 11 )     {
    ( 12 )            Object object = iterator.next();
    ( 13 ) //         if (object instanceof Element)
    ( 14 ) //               System.out.println(((Element)object).getTextNormalize());
    ( 15 )             if (object instanceof Content)
    ( 16 )                   System.out.println(((Content)object).getValue());
    ….This program would work on the same document without the default namespace, hence, it would not be necessary to include “ns” prefix along in the XPath statements (line 6-7) either. Moreover, I was using “org.apache.xerces.parsers.SAXParser” to have successfully retrieve content of <a> from the same document without default namespace in the past.
    I would like to achieve the following objectives if possible:
    ( i ) Exclude DTD and namespace in order to simplifying the parsing process. How this could be done?
    ( ii ) If this is not possible, how to include it in XPath statements (line 6-7) so that the value of <a> is picked up correctly?
    ( iii ) Would changing from “org.apache.xerces.parsers.SAXParser” to “org.ccil.cowan.tagsoup.Parser” make any difference as far as using XPath is concerned?
    ( iv ) Failing to exlude DTD, how to change the lookup of a PUBLIC DTD to a local SYSTEM one and include a local DTD for reference?
    I am running JDK 1.6.0_06, Netbeans 6.1, JDOM 1.1, Saxon6-5-5, Tagsoup 1.2 on Windows XP platform.
    Any assistance would be appreciated.
    Thanks in advance,
    Jack

    Here's an example of using a custom EntityResolver with the standard DocumentBuilder provided by the JDK. The code may or may not be similar for the parsers that you're using.
    import java.io.IOException;
    import java.io.StringReader;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.xml.sax.EntityResolver;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    public class ParseExamples
        private final static String COMMON_XML
            = "<music>"
            +     "<artist name=\"Anderson, Laurie\">"
            +         "<album>Big Science</album>"
            +         "<album>Strange Angels</album>"
            +     "</artist>"
            +     "<artist name=\"Fine Young Cannibals\">"
            +         "<album>The Raw & The Cooked</album>"
            +     "</artist>"
            + "</music>";
        private final static String COMMON_DTD
            = "<!ELEMENT music (artist*)>"
            + "<!ELEMENT artist (album+)>"
            + "<!ELEMENT album (#PCDATA)>"
            + "<!ATTLIST artist name CDATA #REQUIRED>";
        public static void main(String[] argv)
        throws Exception
            // this version uses just a SYSTEM identifier - note that it gets turned
            // into a file: URL
            String xml = "<!DOCTYPE music SYSTEM \"bar\">"
                       + COMMON_XML;
            // this version uses both PUBLIC and SYSTEM identifiers; the SYSTEM ID
            // gets munged, the PUBLIC ID doesn't
    //        String xml = "<!DOCTYPE music PUBLIC \"foo\" \"bar\">"
    //                   + COMMON_XML;
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setValidating(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            db.setEntityResolver(new EntityResolver()
                public InputSource resolveEntity(String publicId, String systemId)
                    throws SAXException, IOException
                    System.out.println("publicId = " + publicId);
                    System.out.println("systemId = " + systemId);
                    return new InputSource(new StringReader(COMMON_DTD));
            Document dom = db.parse(new InputSource(new StringReader(xml)));
            System.out.println("root element name = " + dom.getDocumentElement().getNodeName());
    }

  • Problem with JDOM and schemas

    I'm trying to parse (and validate) an XML document with JDOM.
    My root element is declared in the schaema whixh is asociated to the document.
    But during parsing, an exception saying that my root element is not declared is thrown.
    Can someone axplain to me what can happen ?
    Thank's

    What's this element ?
    My schema is indicated by the xsi:schemeLocation attribute of my root-element .

  • Problem with JDOM and euro character

    Hi,
    I have an xml file including euro characters (�) and starting with :
    <?xml version="1.0" encoding="ISO-8859-15"?>
    as it should probably be.
    However, my problem is that (JDOM and) SAXBuilder doesn't recognize the euro characters and replace them by an unknown character '?'.
    What's wrong and how can I solve it?
    Thanks in advance.

    All right, this is a a part of my code:
    ....SAXBuilder builder = new SAXBuilder( true );
    //create the document
    //this doc contains this tag <RefVersion> data�data </RefVersion>
    Document doc = builder.build( "E:\\test.xml" );
    System.out.print( "before charAt = " + "�".charAt(0) + String.valueOf('\u20ac') );
    String str = "euro�euro";
    System.out.println( "euro�euro ->" + str.replace('\u20ac','O') );
    Element root = doc.getRootElement();
    //recup du noeud RefVersion
    Element version = root.getChild( "RefVersion" );
    str = version.getText();
    System.out.println( "nom= " + version.getName() + " data= " + str );
    System.out.println( "index de � ds euro�euro " + str.replace('\u20ac','O') );
    and the output is:
    before charAt = ��
    euro�euro ->euroOeuro
    nom= RefVersion data= data?data
    index de � ds euro�euro data?data
    So, obviously, it comes from JDOM.

  • Problems with JDom

    In my Jdom program I got the following errors during compilation. It could compile on one machine,
    but it did not on another,even though I made sure the machines are set up properly:
    package com.sun.java.util.collections does not exist
    import com.sun.java.util.collections.*;
    ^
    file com\sun\java\util\collections\List.class not found
    outputter.output(jdomDocument, new FileOutputStream(outputfilename));
    ^
    2 errors
    Same thing with running it. I could run it on one machine, but not another:
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/java/util/collections/Collection
    at org.jdom.input.DefaultJDOMFactory.document(DefaultJDOMFactory.java)
    at org.jdom.input.DOMBuilder.build(DOMBuilder.java)
    at org.bcit.mmsd.lab5.MyJDOMParser.<init>(MyJDOMParser.java:86)
    at org.bcit.mmsd.lab5.Controller.<init>(Controller.java:77)
    at org.bcit.mmsd.lab5.Controller.main(Controller.java:135)

    I've a similar problem. With this code:
    import org.jdom.*; // version 8 beta
    import org.jdom.input.*;
    public static void listChildren(org.jdom.Element current) {
    java.util.List children = current.getChildren();
    Iterator iterator = children.iterator();
    while (iterator.hasNext()) {
    Element child = (Element) iterator.next();
    listChildren(child);
    compiled on NetBeans 3.4, I've got this error:
    incompatible types:
    found : com.sun.java.util.collections.Iterator
    required: java.util.Iterator
    Iterator iterator = children.iterator();
    ????????

  • Formatting problem with JDOM

    friends,
    help me out plz..
    While creating a xml document using JDOM ,
    I am not able to get the formatted xml file.
    program output is:
    <?xml version="1.0" encoding="UTF-8"?>
    <person><name>A</name><name>B</name><name>C</name><name>D</name></person>
    I want the result as:
    <?xml version="1.0" encoding="UTF-8"?>
    <person>
         <name>A</name>
         <name>B</name>
         <name>C</name>
         <name>D</name>
    </person>
    // XMLGenerator.java
    import org.jdom.Element;
    import org.jdom.Document;
    import org.jdom.output.XMLOutputter;
    import java.io.*;
    public class XMLGenerator {
    public static void main(String[] args) throws Exception{
    Element root = new Element("employee");
    while(rs.next()) // rs .. ResultSet
    Element emp_name= new Element("name");
    emp_name.setText(rs.getString(rs.getString("name")));
    root.addContent(emp_name);
    Document doc = new Document(root);
    // serialize it into a file
    try {
    FileOutputStream out = new FileOutputStream("record.xml");
    XMLOutputter serializer = new XMLOutputter();
    serializer .setIndent(true);
    serializer.output(doc, out);
    out.flush();
    out.close();
    catch (IOException e) {
    System.err.println(e);

    try:
    XMLOutputter serializer = new XMLOutputter( " " );
    with the size of the indent you require.
    You dont really need the line: serializer.setIndent(true); if u use this constructor.
    Hope this Helps
    Sam

  • Deserialization Problem with JDOM Document

    HI,
    I am using weblogic7.0 and i have created my own class which implements serializable. I set the object of this class in the ObjectMessage and send it across. Sometime i have to send some vector,sometimes string and sometime a XML document. So i can set these type of objects in my custom serializable object and send it. For sending XML , either i can send it as a string or as u said as Document object. But i want to do send it as a Document object. So i have created a an object of "org.jdom.Document" which implement serializable and setting this object into my custom object and sending this custom object in the objectmessage. But then weblogic throws some exceptions which has to do with deserialization.I am printing the exception below. (without the object of org.jdom.Document this custom object reaches safely and happily:))........can you or anybody tell me what could be the reason..
    weblogic.jms.common.JMSException: Error deserializing object
    at weblogic.jms.common.ObjectMessageImpl.getObject(ObjectMessageImpl.java:140)
    at com.sds.kb.cm.CMMDBReceiver.onMessage(CMMDBReceiver.java:143)
    at weblogic.ejb20.internal.MDListener.execute(MDListener.java:356)
    at weblogic.ejb20.internal.MDListener.transactionalOnMessage(MDListener.java:290)
    at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:271)
    at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:2303)
    at weblogic.jms.client.JMSSession.execute(JMSSession.java:2226)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    ----------- Linked Exception -----------
    weblogic.jms.common.JMSException: Error deserializing object
    at weblogic.jms.common.ObjectMessageImpl.getObject(ObjectMessageImpl.java:140)
    at com.sds.kb.cm.CMMDBReceiver.onMessage(CMMDBReceiver.java:143)
    at weblogic.ejb20.internal.MDListener.execute(MDListener.java:356)
    at weblogic.ejb20.internal.MDListener.transactionalOnMessage(MDListener.java:290)
    at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:271)
    at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:2303)
    at weblogic.jms.client.JMSSession.execute(JMSSession.java:2226)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    any help would be apprciated..
    Akhil

    Are you sure that your object gets serialized in the first place? You could use the writeObject method (explained in Javadoc for java.io.Serializable) to snoop the process.
    I am actually surprised you can serialize a DOM document.
    /Sebastian

  • What's wrong with my XPath statement using dom4j?

    I'm pretty new to XML. However, I did pick up a book and I'm pretty much through it. I got a copy of dom4j and I created a sample XML file. I'm able to parse the data and find out the child elements of root but I'm having problems with using XPath no matter what I do. Here's my code:
    import org.dom4j.*;
    import org.dom4j.io.*;
    import java.util.*;
    import java.io.*;
    public class XMLACL {
      org.dom4j.Document doc;
      org.dom4j.Element root;
      XMLACL(String x) {
        String tempFile = System.getProperty("user.dir") + "/winsudo.xml";
        tempFile = tempFile.replace('\\', '/');
        SAXReader xmlReader = new SAXReader();
        try {
          doc = xmlReader.read(tempFile);
        catch (Exception e) {}
        root = doc.getRootElement();
        //treeWalk();
        //iterateRootChildren("grant");
        XPath xpathSelector = DocumentHelper.createXPath("/grant[@prompt='no']");  
        List results = xpathSelector.selectNodes(doc);
        for (Iterator iter = results.iterator(); iter.hasNext(); ) {
         Element element = (Element) iter.next();
          System.out.println(element.getName());
    }And here's my XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <config>
         <alias name="admin">
              <user>geneanthony</user>
              <user>mike</user>
              <user>rob</user>
         </alias>
         <grant prompt="no" runas="root" service="no">
              <user>geneanthony</user>
              <command>!ALL</command>
         </grant>
         <grant>
              <user>geneanthony</user>
              <group>users</group>
              <command>C:/Program Files/Mozilla Firefox/firefox.exe</command>
         </grant>
         <grant>
              <alias>admin</alias>
              <command>!Panels</command>
         </grant>
    </config>I'm currently getting this error:
    C:\Borland\JBuilder2005\jdk1.4\bin\javaw -classpath "C:\code\java\WinSudo\classes;C:\Borland\JBuilder2005\jdk1.4\jre\javaws\javaws.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\charsets.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\ext\dnsns.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\ext\ldapsec.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\ext\localedata.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\ext\sunjce_provider.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\im\indicim.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\im\thaiim.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\jce.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\jsse.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\plugin.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\rt.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\sunrsasign.jar;C:\Borland\JBuilder2005\jdk1.4\lib\dt.jar;C:\Borland\JBuilder2005\jdk1.4\lib\htmlconverter.jar;C:\Borland\JBuilder2005\jdk1.4\lib\tools.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\jRegistryKey.jar;C:\Borland\JBuilder2005\jdk1.4\lib\hsqldb.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\dom4j-1.6.1.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\syntax.jar;C:\Borland\JBuilder2005\jdk1.4\jre\lib\IzPack-install-3.7.2.jar" winsudo.Main
    java.lang.NoClassDefFoundError: org/jaxen/JaxenException
         at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
         at org.dom4j.DocumentHelper.createXPath(DocumentHelper.java:121)
         at winsudo.XMLACL.<init>(XMLACL.java:26)
         at winsudo.Main.main(Main.java:15)
    Exception in thread "main"
    Can someone tell me what's wrong with my code. None of the samples I've seen came with the XML files so I don't know if I when I start the XPATH I need to use / for the root element, or // or a forward slash and the root name. Can I please get some help!

    Thank you! I didn't haven Jaxen I thought everything was in the package and I must have missed it in the tutorials. That resolved the dropouts and I think I'm good know. I couldn't think for the life of me what I was doing wrong!

  • [XML/XPATH] jaxen : problem with "parent" function

    Hello
    I have a problem with jaxen, when I try to use the XPath function parent :
    When I try this :
    import ...
    DocumentNavigator dn=new DocumentNavigator();
    try {
    objet=dn.getDocument("TESTXPath.xml");
    apath=dn.parseXPath("/Entry/Resultats/step/Population/individu/*");
    result=apath.evaluate(objet);
    System.out.println(result);
    apath=dn.parseXPath("/Entry/Resultats/step/Population/parent::*");
    result=apath.evaluate(objet); // ---> exception
    System.out.println(result);
    catch(Exception e) {
    e.printStackTrace();
    The first result is well displayed, but just before the second, I catch this exception:
    Exception in thread "main" java.lang.NoSuchMethodError: org.jdom.Element.getParent()Lorg/jdom/Element; at org.jaxen.jdom.DocumentNavigator.getParentAxisIterator(DocumentNavigator.java: 252)
    at org.jaxen.expr.iter.IterableParentAxis.iterator(IterableParentAxis.java:82)
    at org.jaxen.expr.DefaultStep.axisIterator(DefaultStep.java:139)
    at org.jaxen.expr.DefaultLocationPath.evaluate(DefaultLocationPath.java:188)
    at org.jaxen.expr.DefaultAbsoluteLocationPath.evaluate(DefaultAbsoluteLocationPat h.java:126)
    at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:107)
    at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:716)
    at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:239)
    at org.jaxen.BaseXPath.evaluate(BaseXPath.java:196)
    at MainTestClass.main(MainTestClass.java:85)
    However, the first query works good and I received list so I'm quite sure that it's not a problem of unfindable elements.
    Finaly I can't be syccessful to use XPath parent function:
    Either I catch an exception, or it returns nothing or empty list
    Isn't the XPath syntax correct in my second expression ?
    Can we do :
    /.../.../parent::* ? ou //individu/parent::* ?

    Thanks
    I think so, but.
    In fact I don't think I'm using different version of JDOM.
    I use eclipse with jdk1.4.2.
    I have downloaded JDOM-b10 and the only things I have done is to extract zip archive and to add all .jar files of the jdom directory in my library path.
    Do this is the only version of JDOM I'm using.
    All works perfectly excepted only the XPath parent method. It's strange that the other methods work fine.
    I don't knnow how to solve this problem ! so if you can help me I be very thankfull.

  • XSLT usage with JDOM problem

    When I try to do an XSL transformation on a JDOM tree
    using Oracle's xml classes from xmlparserv2.jar (includes
    the javax.xml.transform api) I get the following:
    java.lang.ClassCastException: org.jdom.transform.JDOMSource$DocumentReader
         at oracle.xml.jaxp.JXTransformer.transform(JXTransformer.java:201)
    The same code works with xalan/crimson as well as saxon/aelfred, anyone
    seen this and knows a solution? Code snippet:
    private Frame transform(Document in, URL stylesheet) {
         TransformerFactory f = TransformerFactory.newInstance();
         InputStream s = stylesheet.openStream();
         Transformer transformer = f.newTransformer(new StreamSource(s));
         JDOMResult out = new JDOMResult();
         out.setFactory(new FPLNodeFactory());
         transformer.transform(new JDOMSource(in), out);
         s.close();
         return (Frame)out.getDocument().getRootElement().detach();
    I was wondering if there is a problem with the Oracle's impelmentation or am I using it incorrectly.
    Thanks.
    Suhas.

    This forum is mostly reviewed by folks using the XML features in the database (which basically means version 9.2). This is an XDK question--I would post it to Technologies > XML > General.

  • Problems with special characters in InputStream or XPath

    Hello everyone,
    I am having problems with special characters such as ", ', - and so on, everything becomes ? (questionmark). (Not with special nordic characthers (å,æ,ø) though.)
    The encoding of the XML is UTF-8, and the server that holds the webservice is setting encoding to UTF-8 also, so no conflict there.
    What I have done is something like this:
    {code}
    String url = "http://www.formula1.com/rss/news/latest.rss"; // This is not the feed I use, it is a custom XML document
    InputSource is = new InputSource(url);
    DocumentBuilderFactory fct = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = fct.newDocumentBuilder();
    Document doc = builder.parse(is);
    Element rootElement = doc.getDocumentElement();
    XPathFactory factory = XPathFactory.newInstance();
    XPath xPath = factory.newXPath();
    out.print(xPath.evaluate("/rss/channel/title", rootElement)); // The xml is not a RSS feed, this is just an example.
    {code}
    Please let me know what I am doing wrong, or give me a hint of how to solve this in another way.
    Best regards,
    G.Hansen
    Edited by: G.Hansen on Mar 24, 2009 2:39 AM

    Hello, thanks for you reply. I had to rewrite your code a little, and I think that your code would not really compile, if you tried yourself :-)
    I ended up with something like this:
    our environment is running in 1.4 mode, so I could not use the for-each loop :-(
    public String printEntities(String s) {
         char[] sArray = s.toCharArray();
         StringBuffer sb = new StringBuffer();
           for (int i = 0; i < sArray.length; i++) {
             if (sArray[i] > 256)
                  sb.append("&#x" + Integer.toHexString(sArray) + ";");
         } else
              sb.append(sArray[i]);
         return sb.toString();

  • Receiver determination - Xpath expression problem with count

    I am working with a scenario where I pick up records from a JDBC connection and if the number of records I pick up is less than a certain number I want to call a webservice.  If it is greater than the number I want to write out a file to be processed by a different process on the receiving end.  I have created the receiver determination condition with the following conditions:
    (/p1:MT_HOG_Data/row[count(row) > 3] EX)
    (/p1:MT_HOG_Data/row[count(row) <= 3] EX)
    The integration is always processing the second condition no matter how many records come in.  I have tried with and without the multiline option.  Can anyone help with this?
    I have searched through the forum and checked the following links without any resolution:
    http://wiki.sdn.sap.com/wiki/display/XI/XpathConditioninReceiverDetermination
    http://help.sap.com/saphelp_nwpi71/helpdata/EN/ab/13bf7191e73a4fb3560e767a2525fd/frameset.htm
    /people/shabarish.vijayakumar/blog/2006/06/07/customise-your-xpath-expressions-in-receiver-determination
    I can't find any examples where a count of records is checked in the expression editor.  Thanks in advance for any help.

    You can not use the EX operator in that case, because that is used only for node existence checks, not for value checks.
    Do you have a row number in your structure ? Then you could write the xpath expression with that counter tag and value
    Example: you want to send to receiver A if count > 3, else to B:
    you set  /rowNumber EQUAL 4 for sender A
    and /rowNumber NOT EQUAL 4 for sender B
    The condition is applied to the whole document. If one of the node/values are true for that condition, then the whole condition is set to true.
    Problem with that is that the second condition also will be true because nodes for that condition will be found
    better would be to have a rowcount tag in the structure. If that is not possible, you can use the "Enhanced Receiver determination" where you can define a mapping which determines the receivers. There you can do anything complicated you want.
    CSY

  • Problem with using JDom to parse Schema , help

    hi there
    I try to use samples downloaded from following URL to parse a schema stored on my hard drive
    http://www.javaworld.com/javaworld/jw-11-2000/jw-1110-validation3_p.html
    the parseschema() method used in this sample uses SAX to read in the supplied schema URL and build a JDOM Document object. but I change it to read a string of "C:\\EBT Express\\shoes.xsd" and build a JDOM Document Object. but I got IOException saying that the file is not found. anyone out there familiar with JDOM, please help. can I use a string to replace URL?
    thank you.

    hi there
    thank you for your reply. I am just curious about how you run that sample code. when you supply a data to validate, how do you do it?

  • Failing to extract xml value using Jdom & Xpath

    I have a method (getSingleNodeValue()) which when passed an xpatch expression will extract the value of the specified element in the xml document refered to in 'doc'. Assume doc at this point has been initialised as shown below and xmlInput is the buffer containing the xml content.
        SAXBuilder     builder          =     null;
        Document     doc          =     null;
        XPath          xpathInstance     =      null;
        doc     = builder.build(new StringReader(xmlInput));When i call the method, i pass the following xpath xpression
        /TOP4A/PERLODSUMDEC/TINPLD1/text()Here is the method. It basically just takes an xml buffer and uses xpath to extract the value:
        public static String getSingleNodeValue(String xpathExpr) throws Exception{
             Text list = null;
             try {
                  xpathInstance = XPath.newInstance(xpathExpr);
                  list = (Text) xpathInstance.selectSingleNode(doc);
             } catch (JDOMException e) {
                  throw new Exception(e);
             }catch (Exception e){
                  throw new Exception(e);
             return list==null ? "?" : list.getText();
        }The above method always returns "?" i.e. nothing is found so 'list' is null.
    The xml document it looks at is
        <TOP4A xmlns="http://www.testurl.co.uk/enment/gqr/3232/1">   
          <HEAD>
            <Doc>ABCDUK1234</Doc> 
          </HEAD>   
          <PERLODSUMDEC>
            <TINPLD1>10109000000000000</TINPLD1>
          </PERLODSUMDEC>
        </TOP4A>The same method works with other xml documents so i am not sure what is special about this one. There is no exception so the xml is valid xml. Its just that the method always sets 'list' to null. Any ideas?
    Edit
    Here is a running program testing the above:
        import org.jdom.*;
        import org.jdom.input.*;
        import org.jdom.xpath.*;
        import java.io.IOException;
        import java.io.StringReader;
        public class XpathTest {
             public static String getSingleNodeValue(String xpathExpr, String xmlInput) throws Exception{
                 Text list = null;
                  SAXBuilder  builder           =   null;
                  Document    doc                    =   null;
                  XPath       xpathInstance   =   null;
                 try {
                      builder     = new SAXBuilder();     
                      doc          = builder.build(new StringReader(xmlInput));
                     xpathInstance = XPath.newInstance(xpathExpr);
                     list = (Text) xpathInstance.selectSingleNode(doc);
                 } catch (JDOMException e) {
                     throw new Exception(e);
                 }catch (Exception e){
                     throw new Exception(e);
                 return list==null ? "Nothing Found" : list.getText();
             public static void main(String[] args){
                  String xmlInput1 = "<TOP4A xmlns=\"http://www.testurl.co.uk/enment/gqr/3232/1\"><HEAD><Doc>ABCDUK1234</Doc></HEAD><PERLODSUMDEC><TINPLD1>10109000000000000</TINPLD1></PERLODSUMDEC></TOP4A>";
                  String xpathExpr = "/TOP4A/PERLODSUMDEC/TINPLD1/text()";
                  XpathTest xp = new XpathTest();
                  try {
                       System.out.println(xp.getSingleNodeValue(xpathExpr, xmlInput1));
                  } catch (Exception e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
        }When i run the above, the output is
        Nothing foundEdit
    I have run some further testing and it appears that if i remove the namespace url it does work. Not sure why yet. Is there any way i can tell it to ignore the namespace?
    Edited by: ziggy on Sep 3, 2011 4:57 PM

    ziggy wrote:
    <TOP4A xmlns="http://www.testurl.co.uk/enment/gqr/3232/1">   
    <HEAD>
    <Doc>ABCDUK1234</Doc> 
    </HEAD>   
    <PERLODSUMDEC>
    <TINPLD1>10109000000000000</TINPLD1>
    </PERLODSUMDEC>
    </TOP4A>
    It works fine, the problem is not with namespace, it is with url have given.
    Editing:
    Found a way to say the program to ignore namespace.
    You have to use Xpath.addNamespace(prefix,uri), and pass the prefix to your pattern string.
    If not clear refer the below code:
    import org.jdom.*;
        import org.jdom.input.*;
        import org.jdom.xpath.*;
        import java.io.IOException;
        import java.io.StringReader;
        public class XpathTest {
             public static String getSingleNodeValue(String xpathExpr, String xmlInput) throws Exception{
                 Text list = null;
                  SAXBuilder  builder           =   null;
                  Document    doc                    =   null;
                  XPath       xpathInstance   =   null;
                 try {
                      builder     = new SAXBuilder();     
                      doc          = builder.build(new StringReader(xmlInput));
                     xpathInstance = XPath.newInstance(xpathExpr);
                        xpathInstance.addNamespace("ns","http://www.testurl.co.uk/enment/gqr/3232/1");
                     list = (Text) xpathInstance.selectSingleNode(doc);
                 } catch (JDOMException e) {
                     throw new Exception(e);
                 }catch (Exception e){
                     throw new Exception(e);
                 return list==null ? "Nothing Found" : list.getText();
             public static void main(String[] args){
                  String xmlInput1 = "<TOP4A xmlns=\"http://www.testurl.co.uk/enment/gqr/3232/1\"><HEAD><Doc>ABCDUK1234</Doc></HEAD><PERLODSUMDEC><TINPLD1>10109000000000000</TINPLD1></PERLODSUMDEC></TOP4A>";
                  String xpathExpr = "/ns:TOP4A/ns:PERLODSUMDEC/ns:TINPLD1/text()";
                  XpathTest xp = new XpathTest();
                  try {
                       System.out.println(xp.getSingleNodeValue(xpathExpr, xmlInput1));
                  } catch (Exception e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
        }Edited by: 833545 on Sep 8, 2011 11:35 PM

Maybe you are looking for

  • TRCS 2LIS_03_BF_TR - CUBE 0IC_C03

    Hi Gurus TI am unable to solve the routine for RCS 2LIS_03_BF_TR -> CUBE 0IC_C03. It is giving me the following error. E:In PERFORM or CALL FUNCTION "ROUTINE_9998", the actual parameter "SOURCE_PACKAGE" is incompatible with the formal parameter "DATA

  • Why is iTunes saying my iPod is corrupted and how do I fix it?

    I got a new computer for work, downloaded iTunes and connected my iPod classic (20GB). I added a few songs to my library before I connected the iPod. Once connected, my iPod appeared but after trying to transfer music an error occured. iTunes stated

  • My i photo tells me to update software, but my software is fully updated but i photo still will not open?

    HI All, hopefully some one can help me with this one- its driving me crazy! I have a Mac desktop computer. When i click on my i photo icon, it tells me to update software and will not let me go into i photo or see any of my pictures. However i have t

  • KM Scenario

    Hi, I've the following scenario. I want to customize the KM with FlexiUI. i want to change and trigger approval before publication of that change. Can Flexible UI handle both or should i use the KM API along with my FlexiUI code to trigger the publis

  • Final Cut Pro dropping Frames on playback

    I am editing a multi cam video in final Cut Pro. I have set playback to proxy media. I have 250gb free hard drive and 8gb ram. I have an IMac that isnt a year old yet. I have previously completed a music video, excactly the same composition of 3 came