This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Performance and the fly likes Help me with a regular expression to speed up the performance ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Performance
Reply locked New topic
Author

Help me with a regular expression to speed up the performance ??

kathir je
Greenhorn

Joined: Jun 07, 2006
Posts: 12
Hi,

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

<Shares>
<bookDetails bookName="How to Learn English" bookAuthor="English Writer">
<Chapter chapterName="From Alphabetes" chapterPage="23"/>
</bookDetails>
<company>
<name>test</name>
<address>test address</address>
<contact>test contact</contact>
<C02>10.5</C02>
</company>
</Shares>

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

Input: bookName

Output: How to Learn English

Input: address

Output: test address

Input : C02 --> The element name has numeric character too

Output: 10.5

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 ???

Thanks,
Kathir

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

Hi Kathir. Please don't post the same post to multiple forums. I think your other post is better placed, in the XML forum. So I'm going to lock this topic now.

Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help me with a regular expression to speed up the performance ??
 
Similar Threads
Searching the XML string content using Regular Expression
XPath expression constrained by a predicate doesn't work (//element[@attribute="value"])
XPATH question
parsing data and storing in the xml
how to get the whole NodeList