tags:

views:

67

answers:

1

There is one thing I really love about LXML, and that the E builder. I love that I can throw XML together like this:

message = E.Person(
  E.Name(
    E.First("jack")
    E.Last("Ripper")
  )
  E.PhoneNumber("555-555-5555")
)

To make:

<Person>
  <Name>
    <First>Jack</First>
    <Last>Ripper</Last>
  </Name>
  <PhoneNumber>555-555-5555</PhoneNumber>
</Person>

As opposed to the painstaking way DOM works.

I am going to be moving a bunch of my software to Java soon and it is very very heavy on its usage of E. Does Java have anything near equivalent to that usage?

+2  A: 

will be hard with pure Java, but if you can use Groovy in your projects then you could use the MarkupBuilder which comes very close to what you're asking for

def xml = new MarkupBuilder(writer)
xml.records() {
  car(name:'HSV Maloo', make:'Holden', year:2006) {
    country('Australia')
    record(type:'speed', 'Production Pickup Truck with speed of 271kph')
  }
}
Stefan De Boey
Just to mention: groovy compiles to java so it can be easily used.
Piotr Czapla
still you won't be able to write it the way you do it in groovy. the question was too have something similar.
Stefan De Boey