Very basic feature of Java is name and type safety. How it will work with your example? If you want something like XML inlining than look for some scripting language. For example Groovy has excelent XML support via GroovyMarkup and GPath.If you want excelent XML support in Java look for XMLBeans. This will keep your Java code name and type safe with features like XPath and XQuery.
+1
I don't understand why people are arguing so much about something so simple as java and XML interoperability. It might not be that standardized, but it is inherently simple.
Various tools exist, from dedicated libraries to scripting languages, as stated. Do people want to get back to C/C++ prepocessor hell ? I strongly believe the Java language syntax, although not always perfect, is way productive enough, particularly with the help of the good IDE we have nowadays. I send much more time defining my object model and running test sessions, than typing code.
I believe that solid and fast standard libraries will do more to promote java and enhance developer experience much more than turning java into Groovy. Not that i do not like Groovy, on the contrary i believe it is an excellent initiative, that i personnaly used in project that are now in production. But you don't need to include it's features into the java language and plateform itself.
I successfuly use JXpath when i need to apply XPath quering to java object trees (mainly parsed XML read via Xerces), it is very cool. If ever i need some more efficient query over an object tree, i build it myself, with my own indexes.
And if ever somebody would like some readable syntax (as it seems to be all about) with high performance implementation, what about something like :
XPathObject myXPathObject = new XPathObject(Person.class, "//Person/Address[City='?']");
DomTree mySubTree = myXPathObject.XPathQuery(myXMLDoc, "New-York");
DomTree mySubTree2 = myXPathObject.XPathQuery(myXMLDoc2, "Toronto");
or in a more concise way if you don't want to reuse the query builder :
DomTree mySubTree = myXMLDoc.XPathQuery("//Person/Address[City='Toronto']");
Maybe such a library exists, by the way, but i did not bother look for it as what i use everyday really satisfies me.
Sorry for people who do not like the "readability" of this code, but for myself a java developer, it is much more readable than all the XML bracketted elements. Additionally i don't need to do the mental switch from java syntax to XML syntax while reading the code.
My 2 cents,
Christian