Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Eclipse Collections Categorically: Level up your programming game
this week in the
Open Source Projects
forum!
Planet Bob
Greenhorn
+ Follow
news
2
Posts
0
Threads
since May 27, 2010
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads
Recent posts by Planet Bob
How can i get XPath of the XML Node using Java API without DTD and XSD
To fix this issue, store the count for XPath itself rather than the tag.
ALSO NOTE
that XPath has "1" as starting index, not the ZERO.
public class SAXCreateXPath extends DefaultHandler { // map of all encountered tags and their running count private Map<String, Integer> xPathCount = new HashMap<String, Integer>(); // keep track of the succession of elements private Stack<String> tags = new Stack<String>();; /** * Construct the XPath expression */ private String getCurrentXPath(String child) { String str = "//"; boolean first = true; for (String tag : tags) { if (first) str = str + tag; else str = str + "/" + tag; str += "[" + xPathCount.get(str) + "]"; first = false; } if (child != null) { str = str + (first ? "" : "/") + child; } return str; } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { String xPath = getCurrentXPath(localName); int count = (xPathCount.get(xPath) == null) ? 0 : xPathCount.get(xPath); xPathCount.put(xPath, 1 + count); tags.push(localName); System.out.println(getCurrentXPath()); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { tags.pop(); } }
show more
11 years ago
XML and Related Technologies
spring 3 and tiles 2.2.1 integration not working for me
you must have done something else too. As it is not working for me. I've Spring 3.0.2 rather than 3.0.1.
See if you can help me. Meanwhile, I'll still dig out.
show more
15 years ago
Spring