Created
November 27, 2021 12:38
-
-
Save sheerazam/82e0d2810986e4c9418e56ba3012bb91 to your computer and use it in GitHub Desktop.
How to Parse Xml using Kotlin in 2021
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleXmlTest { | |
val xmlToParse = """ | |
<?xml version="1.0"?> | |
<!DOCTYPE DATA_FETCH SYSTEM "http://www.redata.com/Xml/DATA_FETCH.dtd"> | |
<DATA_FETCH> | |
<REC> | |
<COL NAME="SELLER4_MOBILEPHONE" VALUE=""/> | |
<COL NAME="SELLER_EMAIL" VALUE=""/> | |
<COL NAME="SELLER_CITY" VALUE=""/> | |
<COL NAME="SELLER3_HOMEPHONE" VALUE=""/> | |
<COL NAME="SELLER4_FULLNAME" VALUE=""/> | |
<COL NAME="BUYER4_ADDRESS1" VALUE=""/> | |
<COL NAME="BUYER3_WORKPHONE" VALUE=""/> | |
<COL NAME="BUYER4_WORKPHONE" VALUE=""/> | |
</REC> | |
</DATA_FETCH> | |
""".trimIndent() | |
@Test | |
fun testXMLParse() { | |
val serializer: Serializer = Persister() | |
val dataFetch = serializer.read(DataFetch::class.java, xmlToParse) | |
assertEquals(dataFetch.REC.size, 8) | |
assertEquals(dataFetch.REC.first().name, "SELLER4_MOBILEPHONE") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment