There is one thing I really love about LXML, and that the E builde开发者_Go百科r. 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?
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')
}
}
精彩评论