xpath_wizard.jsp
来自「jakarta-taglibs」· JSP 代码 · 共 201 行
JSP
201 行
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<%@ taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags" %>
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.dom4j.*" %>
<%@ page import="org.dom4j.io.*" %>
<%@ page import="org.apache.taglibs.xtags.util.StringHelper" %>
<head>
</head>
<body>
<h2>XPath evaluator</h2>
<p>This will evaluate an XPath expression on a given document
(which can be any valid URL to an XML document)
and an optional context XPath expression.
The context XPath expression allows an XPath expression to be
applied to a certain part of the document.</p>
<br />
<%
String uri = request.getParameter("uri");
if ( uri == null ) {
//uri = "http://p.moreover.com/cgi-local/page?c=Java%20news&o=rss";
uri = "/much_ado.xml";
}
String contextPath = request.getParameter("contextPath");
if ( contextPath == null ) {
contextPath = ".";
}
String path = request.getParameter("path");
if ( path == null ) {
path = "//STAGEDIR";
}
String sortText = request.getParameter("sort");
boolean sort = false;
if ( sortText == null ) {
sortText = "";
}
else {
sort = sortText.equalsIgnoreCase( "true" );
}
String sortPath = request.getParameter("sortPath");
if ( sortPath == null ) {
sortPath = ".";
}
String distinctText = request.getParameter("distinct");
boolean distinct = false;
if ( distinctText == null ) {
distinctText = "";
}
else {
distinct = distinctText.equalsIgnoreCase( "true" );
}
%>
<form method="GET" action="<%= request.getRequestURI() %>">
<table cellspacing="0" cellpadding="4" bgcolor="#000000" border="1" width="100%">
<tr>
<td bgcolor="#dddddd">
Document URI
</td>
<td bgcolor="#eeeeee" colspan="3">
<input type="text" name="uri" value="<%= uri %>" size="100"/>
</td>
</tr>
<tr>
<td bgcolor="#dddddd">
Context XPath expression
</td>
<td bgcolor="#eeeeee" colspan="3">
<input type="text" name="contextPath" value="<%= contextPath %>" size="100"/>
</td>
</tr>
<tr>
<td bgcolor="#dddddd">
XPath expression to process
</td>
<td bgcolor="#eeeeee" colspan="3">
<input type="text" name="path" value="<%= path %>" size="100"/>
</td>
</tr>
<tr>
<td bgcolor="#dddddd">
Sort results
<input type="checkbox" name="sort" value="true"
<% if ( sort ) out.print( " checked " ); %>
/>
</td>
<td bgcolor="#dddddd">
Sort by XPath expression
</td>
<td bgcolor="#eeeeee">
<input type="text" name="sortPath" value="<%= sortPath %>"/>
</td>
<td bgcolor="#dddddd">
Distinct values (when sorting)
<input type="checkbox" name="distinct" value="true"
<% if ( distinct ) out.print( " checked " ); %>
/>
</td>
</tr>
<tr>
<td bgcolor="#dddddd" colspan="4" align="center">
<input type="SUBMIT" value="Evaluate" />
</td>
</tr>
</table>
</form>
<br >
<%
String fullURI = uri;
boolean isFullURL = true;
if ( uri != null && uri.length() > 0 ) {
// if no absolute URL is being used
if ( uri.indexOf( ':' ) < 0 ) {
isFullURL = false;
String root = request.getContextPath();
if ( root != null ) {
fullURI = root + uri;
}
}
String asXmlUrl = "";
if ( path != null && path.length() > 0 ) {
asXmlUrl = "xpath.xml?uri="
+ java.net.URLEncoder.encode(uri)
+ "&path=" + path + "&contextPath=" + contextPath;
if ( sortPath != null ) {
asXmlUrl += "&sortPath=" + sortPath;
}
if ( sort ) {
asXmlUrl += "&sort=true";
}
if ( distinct ) {
asXmlUrl += "&distinct=true";
}
}
%>
<h3>
<a href="<%= fullURI %>" target="xml.source">View source XML</a>
</h3>
<h3>
<a href="<%= asXmlUrl %>" target="xml.results">View results as XML</a>
</h3>
<br />
<h3>Results</h3>
<table width="100%" cellspacing="0" cellpadding="2" bgcolor="#000000" border="1">
<%
System.out.println( "About to parse: " + uri );
if ( isFullURL ) {
%>
<xtags:parse url="<%= uri %>"/>
<%
}
else {
%>
<xtags:parse uri="<%= uri %>"/>
<%
}
%>
<xtags:forEach id="result" select="<%= path %>" sort="<%= ( sort ) ? sortPath : null %>" distinct="<%= distinct %>">
<%
String text = "";
if ( result instanceof String ) {
text = (String) result;
}
else if ( result instanceof Node ) {
Node node = (Node) result;
text = StringHelper.encodeHTML(node.asXML());
}
else if ( result != null ) {
text = result.toString();
}
%>
<tr bgcolor="#eeeeee">
<td><%= text %></td>
</tr>
</xtags:forEach>
<%
}
%>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?