2
* Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
4
* This software is open source.
5
* See the bottom of this file for the licence.
7
* $Id: XPathValueOf.java,v 1.4 2005/01/29 14:52:57 maartenc Exp $
10
package org.dom4j.samples;
12
import org.dom4j.Document;
13
import org.dom4j.DocumentHelper;
14
import org.dom4j.XPath;
17
* A utility program which performs XPath expressions on one or more XML files
18
* and outputs the valueOf the XPath expression. It is similar to the
19
* <code>grep</code> command on Unix but uses XPath valueOf for matching
21
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
22
* @version $Revision: 1.4 $
24
public class XPathValueOf extends SAXDemo {
26
protected XPath xpath;
28
public static void main(String[] args) {
29
run(new XPathValueOf(), args);
32
public XPathValueOf() {
35
public void run(String[] args) throws Exception {
36
if (args.length < 2) {
37
printUsage("{options} <XPath expression> <xml file(s)>");
41
for (int i = 0, size = args.length; i < size; i++) {
43
if (arg.startsWith("-")) {
49
Document document = parse(arg);
56
public void setXPath(String xpathExpression) {
57
xpath = DocumentHelper.createXPath(xpathExpression);
60
protected void process(Document document) throws Exception {
61
String value = xpath.valueOf(document);
65
protected void readOptions(String arg) {
70
* Redistribution and use of this software and associated documentation
71
* ("Software"), with or without modification, are permitted provided that the
72
* following conditions are met:
74
* 1. Redistributions of source code must retain copyright statements and
75
* notices. Redistributions must also contain a copy of this document.
77
* 2. Redistributions in binary form must reproduce the above copyright notice,
78
* this list of conditions and the following disclaimer in the documentation
79
* and/or other materials provided with the distribution.
81
* 3. The name "DOM4J" must not be used to endorse or promote products derived
82
* from this Software without prior written permission of MetaStuff, Ltd. For
83
* written permission, please contact dom4j-info@metastuff.com.
85
* 4. Products derived from this Software may not be called "DOM4J" nor may
86
* "DOM4J" appear in their names without prior written permission of MetaStuff,
87
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
89
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
91
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
92
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
94
* ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
95
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
96
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
97
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
98
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
99
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
100
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
101
* POSSIBILITY OF SUCH DAMAGE.
103
* Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
105
* $Id: XPathValueOf.java,v 1.4 2005/01/29 14:52:57 maartenc Exp $