Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

processing xml file in java  RSS feed

ved gunjan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! All
I have to process/handle a xml file in my java for this i'm using JAXB API.This is what i have understood uptill now regarding JAXB. JAXB producing the Java files from the XML schema and then unmarshalling xml data into java object.In the unmarshalling process you begin with a valid XML file and convert it to Java objects that are instances of the classes that were created by the JAXB schema on the whole You will perform two basic activities when working with a data binding solution. You will compile the schema into Java source files that contain interfaces and classes. You will then use these generated classes along with the APIs provided for handling generated files.
Java files are then created by giving the following command

java -jar [JAXB_LIB]\ abc.xsd .Suppose it generates the corrosponding java files in the folder structure

Now to unmarshal XML content into a content tree of data objects, you first create a JAXBContext instance for handling schema-derived classes, then create an Unmarshaller instance, and then finally unmarshal the XML content. For example, if the generated classes are in a package named MyPackage and the XML content is in a file named abc.xml:

JAXBContext jc = JAXBContext.newInstance( "MyPackage" );
Unmarshaller u = jc.createUnmarshaller();
PurchaseOrder po =
(PurchaseOrder)u.unmarshal( new FileInputStream( "abc.xml" ) );

Now i want to know whether i have to invoke the command
java -jar [JAXB_LIB]\abc.xsd
dynamically using the java.lang.Runtime execute(String command)
to get the generated java classes in some folder,as we work on the generated java classes to unmarshal it.

Any help will be greatly appreciated.
Many Regards
Ved Gunjan.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!