Example usage for org.dom4j.rule Rule Rule

List of usage examples for org.dom4j.rule Rule Rule

Introduction

In this page you can find the example usage for org.dom4j.rule Rule Rule.

Prototype

public Rule() 

Source Link

Usage

From source file:org.dom4j.samples.rule.SongFilter.java

License:Open Source License

public Document filtering(org.dom4j.Document doc) throws Exception {
    Element resultRoot = DocumentHelper.createElement("result");
    this.resultDoc = DocumentHelper.createDocument(resultRoot);

    Rule songElementRule = new Rule();
    songElementRule.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3"));
    songElementRule.setAction(new SongElementBuilder());

    Rule titleTextNodeFilter = new Rule();
    titleTextNodeFilter.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3/title"));
    titleTextNodeFilter.setAction(new NodeTextFilter());

    this.style = new Stylesheet();
    this.style.addRule(songElementRule);
    this.style.addRule(titleTextNodeFilter);

    style.run(doc);//  w  ww  .j  a  v a  2 s. c om

    return this.resultDoc;
}