aspose file tools
The moose likes Java in General and the fly likes regex to get cdata value Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "regex to get cdata value" Watch "regex to get cdata value" New topic
Author

regex to get cdata value

divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110


i need to get cdata value from this <user:user.clearTextPassword xsi:type=\"string\"><![CDATA[xyz123]]></user:user.clearTextPassword> any help


SCJP - 5.0
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 774

Go through following docs that may help you

java.util.regex.Pattern
java.util.regex.Matcher :- matches() , start(), end(), group()


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Assuming this is part of an xml file, I wouldn't use regex. Because the regex will become very complex (and hard to read) as your xml file becomes more complex.
I would use an xml parser which will handle the xml-namespaces, the CDATA and more.

Btw: why are there slashes by the attribute? Did you copy it from a String literal?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12271
    
    1
Since the CDATA section tag is always written the same way, why not plain String matching such as indexOf() ?

Bill



Java Resources at www.wbrogden.com
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

I'm a great fan of regex but not for parsing XML. Since you are only interested in one element, to me it would make much more sense to use SAX.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regex to get cdata value
 
Similar Threads
Print out values of xml tags
Why b.c.d is correct?
JAXB: Creating a message with a CDATA section
attributes
Illegal XML character &#x0;