xpathtest.java
来自「Java的面向对象数据库系统的源代码」· Java 代码 · 共 71 行
JAVA
71 行
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: XPathTest.java,v 1.2 2003/07/07 10:30:30 per_nyfelt Exp $package test.ozoneDB.xml.dom4j;import junit.framework.TestCase;import org.dom4j.Document;import org.dom4j.Element;import org.ozoneDB.ExternalDatabase;import org.ozoneDB.xml.dom4j.O3DocumentHelper;import java.util.List;/** * $Id: XPathTest.java,v 1.2 2003/07/07 10:30:30 per_nyfelt Exp $ */public class XPathTest extends TestCase { final String addressXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<addresses>" + "<address name=\"Andreas\"><town>New York</town></address>" + "<address name=\"Lars\"><town>Los Angeles</town></address>" + "</addresses>"; ExternalDatabase db; public XPathTest(String methodName) { super(methodName); } public void setUp() { try { db = ExternalDatabase.openDatabase("ozonedb:remote://localhost:3333"); O3DocumentHelper.configure(db); } catch (Exception e) { e.printStackTrace(); } } public void tearDown() { try { if ((db != null) && (db.isOpen())) { db.close(); } } catch (Exception e) { fail(e.toString()); } } public void testXPathl() { try { Document doc; System.out.println("Parsing string"); doc = O3DocumentHelper.parseText(addressXML); Element root = doc.getRootElement(); List nodes = root.selectNodes("/addresses/address/town"); assertEquals("expected 2 nodes", 2, nodes.size()); root.selectObject("//address@name='Lars'"); O3DocumentHelper.deleteDocument(doc); } catch (Exception e) { e.printStackTrace(); fail(e.toString()); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?