Thursday, 20 August 2015

XML : Java XML dynamic parser

I'm looking for a simple solution.

I have a xml file:

  <properties>      <property>          <class>java.lang.String</class>          <value>String value...</value>      </property>      <property>          <class>java.lang.Boolean</class>          <value>true</value>      </property>      <!-- ... others java lang wrapper class -->  </properties>    

I would like to do a dynamic parser.

I know that I can read the xml with org.w3c.dom.* and org.w3c.dom.Node.getTextContent() I can get the value of the tag.

  Class<?> clazz = Class.forName(classTextContent);  // How to convert value to specific clazz?  // if/else (clazz)? Does not look a nice answer.    

Any suggestion?

No comments:

Post a Comment