1 2 3 4 5 6 7 8 | * Core API: abdera.core.0.3.0-incubating.jar (required) * Parser Impl: abdera.parser.0.3.0-incubating.jar (required) * IRI Support: abdera.i18n.0.3.0-incubating.jar (required) * axiom-api-1.2.5.jar (required by core) * axiom-impl-1.2.5.jar (required by core) * geronimo-activation_1.0.2_spec-1.1.jar (any JAF impl is required) * commons-logging-1.0.4.jar * jaxen-1.1.1.jar (required by the core, XPath 实现 ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | package xml.Abdera; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.abdera.Abdera; import org.apache.abdera.model.Document; import org.apache.abdera.model.Entry; import org.apache.abdera.model.Feed; import org.apache.abdera.writer.Writer; import org.apache.abdera.xpath.XPath; public class AbderaFilterFeed implements main.IFilterFeed{ public OutputStream filter(InputStream is, String xpathExpr){ OutputStream os = System.out; // new adbera instance Abdera abdera = Abdera.getNewFactory().getAbdera(); // parse input file stream into Adbera Document object Document<Feed> doc = abdera.getParser().parse(is); //get Feed FOM object Feed feed = doc.getRoot(); //create xpath object XPath xpath = abdera.getXPath(); //specify the xpath expression //String expression = "atom:feed/atom:entry[ " + xpathExpr + "]"; String expression = "atom:feed/atom:entry[atom:content/row:row/row:Customer_Name = 'Ford']"; //generate namespace map Map<String,String> namespaces = new HashMap<String,String>(); namespaces.put("atom", "http://www.w3.org/2005/Atom"); namespaces.put("row", "http://www.ibm.com/xmlns/atom/content/datarow/1.0"); //select nodes using xpath object List entries = xpath.selectNodes(expression, feed.getDocument(), namespaces); //generate output feed Feed output = abdera.newFeed(); for( int i = 0; i < entries.size(); i++ ){ Entry entry = (Entry) entries.get(i); output.addEntry(entry); } //get pretty xml writer and writer to output stream Writer writer = abdera.getWriterFactory().getWriter("prettyxml"); try { writer.writeTo(output, os); } catch (IOException e) { e.printStackTrace(); } return os; } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |