Hi there. Was wondering if anyone could help me on this (hopefully straightforward) question:
I have a test function that accepts an element parameter, and attempts to use DOM to find all child anchor elements below this node, and then find the class attribute for each anchor. The code should...
If this is a really simple application, then you could read the XML directly from your JSP using JSTL XML tags.
http://java.sun.com/products/jsp/jstl/
For anything more complicated, you should really use the MVC design pattern. Have a JavaBean class to model your XML, and have the JSP access...
...is '\' '.'
This then ensures the period is not treated as a special metacharacter.
One way to get round this problem for large pieces of text is:
"\\Q your text containing metachars like . + *\\E"
See also:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html
Cheers, Neil
How about:
Java 5.0:
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/xpath/package-summary.html
Or Xalan:
http://xml.apache.org/xalan-j/apidocs/org/apache/xpath/package-summary.html
Cheers, Neil
A minor variation on Dinesh's (19decsat) answer using a sub for clarity:
foreach (sort byVal keys %hash) {
print "$_ $hash{$_}\n";
}
sub byVal {
return $hash{$b} <=> $hash{$a};
}
Cheers, Neil
Here's a modified version of the regexp which should work:
#!/usr/bin/perl -w
while (<DATA>) {
if (/^ # start of line
\s # a single whitespace
( # start grouping
[0-9]+ # 1 or more digits
\s+ # 1 or more whitespace...
Its quite useful to use the 'x' modifier to explain complex regular expressions:
while (<DATA>) {
if (/^ # start of line
\s # a single whitespace
( # start grouping
[0-9]{1,} # 1 or more digits
\s{5} # exactly 5 spaces
)...
Alternatively, if you intend all instances of your beans to share initialisation strings, then you can have:
public class MyBean {
private static String initValue;
public static void setInitValue(String value) {
initValue = value;
}
}
Then, create and register a...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.