XML is not a source for code. It is, however, capable of describing certain types of data structures (trees, essentially), and interfaces to behavior (e.g. WSDL).
Java can, of course, do that too, but people don't all write in Java (silly people!
) and so, it was decided some time ago that it would be a GoodThing(TM) to have a means of describing data structures (particularly for use in network communications) that was independent of any programming language. For a long time, there were many of these (e.g. tools in XDR/RPC, and in CORBA), but at some point, the world decided to start all over and use XML (I'm cynical enough to believe that this was because XML was trendy ;) but there were some valid arguments about it looking enough like HTML to get through firewalls to and from web servers, and because many of the pre-existing tools were not free, or open source)
HTH
Simon