XML parse node value as string
Posted
by
bharathi
on Stack Overflow
See other posts from Stack Overflow
or by bharathi
Published on 2012-09-23T07:29:51Z
Indexed on
2012/09/23
9:37 UTC
Read the original article
Hit count: 464
My xml file is look like this . I want to get the value node text content as like this .
<property regex=".*" xpath=".*">
<value>
127.0.0.1
</value>
<property regex=".*" xpath=".*">
<value>
val <![CDATA[
<Valve className="org.tomcat.AccessLogValve" exclude="PASSWORD,pwd,pWord,ticket" enabled="true" serviceName="zohocrm" logDir="../logs" fileName="access" format="URI,"PARAM","REFERRER",TIME_TAKEN,BYTES_OUT,STATUS,TIMESTAMP,METHOD,SESSION_ID,REMOTE_IP,"INTERNAL_IP","USER_AGENT",PROTOCOL,SERVER_NAME,SERVER_PORT,BYTES_IN,ZUID,TICKET_DIGEST,THREAD_ID,REQ_ID"/>
]]> test
</value>
</property>
I want to get text as order they specified in a file . Here is my java code .
Document doc = parseDocument("properties.xml");
NodeList properties = doc.getElementsByTagName("property");
for( int i = 0 , len = properties.getLength() ; i < len ; i++) {
Element property = (Element)properties.item(i);
//How can i proceed further .
}
Output Expected :
Node 1 : 127.0.0.1
Node 2 : val <Valve className="org.tomcat.AccessLogValve" exclude="PASSWORD,pwd,pWord,ticket" enabled="true" serviceName="zohocrm" logDir="../logs" fileName="access" format="URI,"PARAM","REFERRER",TIME_TAKEN,BYTES_OUT,STATUS,TIMESTAMP,METHOD,SESSION_ID,REMOTE_IP,"INTERNAL_IP","USER_AGENT",PROTOCOL,SERVER_NAME,SERVER_PORT,BYTES_IN,ZUID,TICKET_DIGEST,THREAD_ID,REQ_ID"/> test
Please suggest your views .
© Stack Overflow or respective owner