I got an xml document that I want to update and I'm looping through the nodes using a recursive function. However I'm having an issue with updating node attributes. I want to hide all the paths from the user and replacing them with a key. This is what I've got so far
XML document example:
<html>
<head>
<title>my document</title>
<link rel="stylesheet" href="/styles/style.css"/>
</head>
<body>
<a href="link1"></a>
<img src="link2"/>
<img src="link3"/>
<img src="link1"/>
<a href="link5"></a>
</body>
</html>
Which is passed through my recursive function which then calls updateNode function to update it
def processNode(n: Node){
if(n.label == "a") {
updateNode(n, "href")
}
}
n.child foreach processNode
}
def updateNode(n: Node, att: String) {
val k: Int = getKey(n.attribute(att).get.toString)
if (k == c){ // if k == c then key does not exists
list += (c -> n.attribute(att).get.toString())
// update node
c = c + 1
} else {
// update node
}}
I've tested .attributes.remove and .attributes.append but they don't seem to be working. I'm assuming that I might need to use .copy but node data type doesn't have .copy.. Elem does