Advertisement
okardec

Untitled

Sep 18th, 2020
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.86 KB | None | 0 0
  1.  
  2.  
  3.     var xmlDocument : Document? = null
  4.     val xPath: XPath = XPathFactory.newInstance().newXPath()
  5.  
  6.     constructor(xmlString: String){
  7.  
  8.         //println(xmlString)
  9.  
  10.         val builderFactory = DocumentBuilderFactory.newInstance()
  11.         var builder: DocumentBuilder? = null
  12.         try {
  13.             builder = builderFactory.newDocumentBuilder()
  14.         } catch (e: ParserConfigurationException) {
  15.             e.printStackTrace()
  16.         }
  17.  
  18.         try {
  19.             xmlDocument = builder!!.parse(ByteArrayInputStream(xmlString.toByteArray()))
  20.         } catch (e: SAXException) {
  21.             e.printStackTrace()
  22.         } catch (e: IOException) {
  23.             e.printStackTrace()
  24.         }
  25.  
  26.         ///println(xmlDocument)
  27.  
  28.     }
  29.  
  30.     fun getString(path: String): String? {
  31.  
  32.         return xPath.compile(path).evaluate(xmlDocument)
  33.  
  34.     }
  35.  
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement