I am stuck in parsing XML which has ":" in its element name.
Sample XML is shown below:
val xml:String = <epp xmlns='urn:ietf:params:xml:ns:epp-1.0'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd'>
<command>
<create>
<host:create xmlns:host='urn:ietf:params:xml:ns:host-1.0'
xsi:schemaLocation='urn:ietf:params:xml:ns:host-1.0host-1.0.xsd'>
<host:name>ns-1.dns.net</host:name>
</host:create>
</create>
<clTRID>TRID-1-100043434343</clTRID>
</command>
</epp>
val dom = scala.xml.XML.loadString(xml)
val name = dom \\ "host:name"
name
always is empty.
I need to get the value of <host:name>
element tag. Please let me know how to get it.
The \\
operator is misleading. It doesn't accept XPath queries, just node names. If you want to filter on the prefix name - the part before the : - that part of the query will have to be in scala. Something like this should work:
val name = (dom \\ "name").filter(_.prefix == "host")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With