i'm trying to parse this xml:
...
<member>
<name>id</name>
<value>
<string>1</string>
</value>
</member>
<member>
<name>description</name>
<value>
<string>sdfsdfsdf</string>
</value>
</member>
...
how to parse only the "<member>" tags with a subordinate "name"-tag = "id"?
i tried:
getroot = multi ( ( getChildren >>> hasName "name" >>> hasText "id") `guards` (isElem >>> hasName "member" ) )
main = do
print <- runX (parseXML "test2.xml" >>> getroot >>> putXmlTree "-")
When you use the filter
hasName "name"
, you get the<name>
tag. That node itself is not a text node, sohasText "id"
fails. Here a modification that seems to work: (I also had to change the type of the argument ofhasText
, maybe a different version of HXT)I’m not an expert of HXT so it might be that there is a much better way to do what you want.