Is there a quick way to convert Java XML objects to scala XML objects?
•
Java
Scala has its own XML library and provides built - in support However, one of the main features of the language is called Java compatibility I want to be able to use Java node objects as I use Scala
My question is:
>What is the fastest way to convert a Java XML container to scala? Is there anything good I can do for you? > Is there a constructor to accept a Java element, such as the scala API?
Solution
So I've dug it. It's the best I can find: http://www.jdom.org/docs/apidocs/org/jdom/output/XMLOutputter.html
The simplest way to use it is implicit:
implicit def javaToScalaXML(jElem: org.jdom.Element): scala.xml.Element = { return XML.loadstring(XMLOuputter.outputString(jElem)) }
For really large XML objects, they are not very beautiful because they are converted to string and then to XML objects, but it is suitable for small and medium-sized objects
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码