Results 1 to 2 of 2
- 04-04-2011, 11:08 AM #1Member
- Join Date
- Feb 2008
- Rep Power
Searching the XML string content using Regular Expression !!!!
I'm having XML content as a string. 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 (Pattern, 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 ????
- 04-04-2011, 12:51 PM #2
Still cross posting after being told off earlier in
How to extract substring from a string based on the condition ??
and after saying
Searching the XML string content using Regular Expression (XML forum at JavaRanch)
Last edited by DarrylBurke; 04-04-2011 at 12:55 PM.
- By mr.ab18 in forum New To JavaReplies: 2Last Post: 08-06-2010, 10:01 PM
- By prof.deedee in forum JDBCReplies: 3Last Post: 02-19-2010, 12:15 PM
- By QkrspCmptPop in forum Advanced JavaReplies: 8Last Post: 01-20-2010, 04:55 AM
- By sidharth in forum Advanced JavaReplies: 2Last Post: 11-11-2009, 06:56 AM
- By ras_pari in forum Advanced JavaReplies: 27Last Post: 10-07-2009, 12:25 PM