Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

xml parsing sample

  Asked By: Vernon    Date: Jul 31    Category: Java    Views: 2108
  

You could use it like sample :


<?xml version="1.0" encoding="UTF-8"?>
<car vin="123fhg5869705iop90">
<!--Description of a car-->
<make>Toyota</make>
<model>Celica</model>
<year>1997</year>
<color>green</color>
<license state="CA">1ABC234</license>
</car>

Element carElement = new Element("car");
Document myDocument = new Document(carElement);

carElement.addAttribute(new Attribute("vin", "123fhg5869705iop90"));

Element make = new Element("make");
make.addContent("Toyota");
carElement.addContent(make);

carElement.addContent(new Element("make").addContent("Toyota"));

carElement.addContent(new
Element("model").addContent("Celica"));
carElement.addContent(new Element("year").addContent("1997"));
carElement.addContent(new Element("color").addContent("green"));
carElement.addContent(new Element("license")
.addContent("1ABC234").addAttribute("state", "CA"));

But if you wanna use the best practice of xml parsing you could use
Stax Parser that it contains Cursor API and Iterator API and simply
programming.

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on xml parsing sample Or get search suggestion and latest updates.




Tagged: