[Dom4j][Rules] What's wromng with this ?

Discussion in 'Java' started by Cram TeXeD, Feb 2, 2004.

  1. Cram TeXeD

    Cram TeXeD Guest

    Hello.
    I got a simple XML (retrieved with DB with Oracle XSU) like this
    <rowset>
    <row num="1">
    <foo>John Doo</foo>
    ...
    <row/>
    <rowset>

    And I'm using
    org.dom4j.rule package this way.

    -----------------------------------------
    package xx.xx.xxx.dirty.sources;

    import org.dom4j.Document;
    import org.dom4j.DocumentHelper;
    import org.dom4j.Element;
    import org.dom4j.Node;
    import org.dom4j.rule.Action;
    import org.dom4j.rule.Rule;
    import org.dom4j.rule.Stylesheet;
    import org.dom4j.tree.DefaultDocument;
    import org.dom4j.tree.DefaultElement;

    public class DirtyXsuPersonne implements DirtyTransformSource {


    Stylesheet selector = new Stylesheet();
    Document toRet;
    Element root;
    String usecase="";

    public DirtyXsuPersonne(String useCase){
    this.usecase = useCase;
    selector.addRule(new
    Rule(DocumentHelper.createPattern("/rowset"), new headerBlock()));
    selector.addRule(new
    Rule(DocumentHelper.createPattern("/rowset/row"), new rowBlock()));
    selector.addRule(new
    Rule(DocumentHelper.createPattern("/rowset/row/*"), new dataBlock()));
    }

    public Document run(Document doc) throws Exception {
    selector.run(doc);
    return toRet;
    }

    private class headerBlock implements Action {
    public void run(Node node) throws Exception {
    root = new DefaultElement("transaction");
    toRet = new DefaultDocument(root);
    root.addAttribute("application","MyApp");
    }
    }

    private class rowBlock implements Action {
    public void run(Node node) throws Exception {
    root.addElement("usecase",usecase);
    }
    }
    private class dataBlock implements Action {
    public void run(Node node) throws Exception {
    Element data = new DefaultElement("data");
    data.addAttribute("name",node.getName());
    Element value = new DefaultElement("value");
    value.addText(node.getText());
    data.add(value);
    root.add(data);
    }
    }
    }


    -----------------------------------------

    But it seems to only fire first rule "/rowset".
    If I flip rules, it always fire the first.
    As the dom4j mailing list is down, I post this here.
    Do someone got an idea ?

    Thanks ?

    8:0) Cram TeXeD
    --
    "La réalité, c'est ce qui refuse de disparaître
    quand on a cessé d'y croire." (Philip K.Dick)
    <http://texed75.free.fr>
    Cram TeXeD, Feb 2, 2004
    #1
    1. Advertising

  2. Cram TeXeD

    Cram TeXeD Guest

    On Mon, 02 Feb 2004 10:05:38 +0100, < Cram TeXeD > dit :

    >Hello.
    >I got a simple XML (retrieved with DB with Oracle XSU) like this
    ><rowset>
    > <row num="1">
    > <foo>John Doo</foo>
    > ...
    > <row/>
    ><rowset>
    >
    >And I'm using
    >org.dom4j.rule package this way.


    Ok. There's nobody to answer my question ? I answering myself !

    You have to use StyleSheet appyTemplate methode inside Action
    implented methode.

    8:0) Cram TeXeD
    --
    "On ne peut pas ne pas communiquer"
    axiome n°1 de Paul Watzlawick
    <http://texed75.free.fr>
    Cram TeXeD, Feb 2, 2004
    #2
    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. Wolfgang
    Replies:
    0
    Views:
    628
    Wolfgang
    Jul 9, 2003
  2. Stefan Siegl
    Replies:
    2
    Views:
    731
    David Zimmerman
    Jul 17, 2003
  3. Timo Nentwig
    Replies:
    0
    Views:
    862
    Timo Nentwig
    Feb 4, 2004
  4. Yoel Spotts

    jdom vs. dom4j

    Yoel Spotts, Feb 10, 2004, in forum: Java
    Replies:
    1
    Views:
    9,134
    Dale King
    Feb 13, 2004
  5. Kimos
    Replies:
    0
    Views:
    582
    Kimos
    Apr 14, 2004
Loading...

Share This Page