Results 1 to 2 of 2
  1. #1
    j_kathiresan is offline Member
    Join Date
    Feb 2008
    Posts
    12
    Rep Power
    0

    Default Searching the XML string content using Regular Expression !!!!

    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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    Still cross posting after being told off earlier in
    How to extract substring from a string based on the condition ??
    and after saying
    Quote Originally Posted by j_kathiresan View Post
    Sorry about that. i'll make sure that i don't cross post the same matter.
    Searching the XML string content using Regular Expression (XML forum at JavaRanch)

    db
    Last edited by DarrylBurke; 04-04-2011 at 12:55 PM.

Similar Threads

  1. Help with regular expression
    By mr.ab18 in forum New To Java
    Replies: 2
    Last Post: 08-06-2010, 10:01 PM
  2. regular expression
    By prof.deedee in forum JDBC
    Replies: 3
    Last Post: 02-19-2010, 11:15 AM
  3. regular expression
    By QkrspCmptPop in forum Advanced Java
    Replies: 8
    Last Post: 01-20-2010, 03:55 AM
  4. Replies: 2
    Last Post: 11-11-2009, 05:56 AM
  5. regular expression
    By ras_pari in forum Advanced Java
    Replies: 27
    Last Post: 10-07-2009, 12:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •