File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
XML and Related Technologies
Searching the XML string content using Regular Expression
Joined: Jun 07, 2006
Apr 04, 2011 04:25:46
I'm having XML content as a
. I'm using W3C dom for getting values from the XML.
I've a very large XML file with attributes, elements similar like below
<bookDetails bookName="How to Learn English" bookAuthor="English Writer">
<Chapter chapterName="From Alphabetes" chapterPage="23"/>
Currently I've written a method which accepts Root Element and searchable name to find the corresponding attribute or element and gets the value.
The method will get the value from a element or an attribute matching the given name.
I've used XPathAPI.selectNodeList to retrieve the value. I've used the below XPATH to check the given searchable name in both attribute and in element
xpath = "//*[@" + inAttr + "]";
xpathElement = "//" + inAttr + "/text()";
NodeList nodelist = XPathAPI.selectNodeList(root, xpath);
NodeList nodelist = XPathAPI.selectNodeList(root, xpathElement)
Sample Input and Output as follows
Output: How to Learn English
Output: test address
Input : C02 --> The element name has numeric character too
Problem: The XPATHAPI.selectNodeList() causes performance problem and it takes more time to search and gets the value.
I've planned to use regular expression (
, Matcher) to search and get the values from the XML string.
Can anyone please let me know the regular expression with a code snippet to retrieve value either from a element or an attribute
which matches the element or attribute name ???
Joined: May 03, 2008
Apr 04, 2011 06:09:48
kathir, on another occasion and forum you wrote, after you had been referred to
JavaRanch FAQ page:
Sorry about that. i'll make sure that i don't cross post the same matter.
So why weren't you forthright this time around?
There are no new questions, but there may be new answers.
Joined: Oct 14, 2005
Apr 04, 2011 09:48:49
If you're asking for a regex which can extract data from an XML document, such things don't exist. The complexity of XML is at a level higher than the complexity of regex.
I agree. Here's the link:
subject: Searching the XML string content using Regular Expression
Help me with a regular expression to speed up the performance ??
parsing data and storing in the xml
XPath expression constrained by a predicate doesn't work (//element[@attribute="value"])
how to get the whole NodeList
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015