<span style="font-family: courier new,monospace;">Adding some code to go along with my last post:<br><br>main = do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [tree] <- runX (readDocument [(a_validate, "0")] "
text.xml")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [</span><span style="font-family: courier new,monospace;">fooDoc</span><span style="font-family: courier new,monospace;">
] <- runX (constA tree >>> processChildren isFoo)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [expanded] <- runX (constA tree >>> processTopDown (expandNode fooDoc `when` hasName "bar"))
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [status] <- runX (constA expanded >>> writeDocument [] "-" >>> getErrStatus)
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (putStrLn . show) status</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
where<br> expandNode :: (ArrowXml a) => XmlTree -> a XmlTree XmlTree<br> expandNode :: (ArrowXml a) => XmlTree -> a XmlTree XmlTree</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
<span style="font-weight: bold;">expandNode foos = this -- what here???</span><br> isFoo = deep (hasName "foo")<br><br></span>The issue is that in 'expandNode', I have an XmlTree (foos) and an arrow whose input is the node to be replaced (also an XmlTree), but I need a String and an arrow whose input is the XmlTree (foos):
<br><br>expandNode' :: (ArrowXml a) => String -> a XmlTree XmlTree<br>expandNode' name = processChildren (hasAttrValue "name" name)<br><br>Somewhat related, if the output of an arrow is a string, can I get access to that string without using 'runX':
<br><a href="http://www.fh-wedel.de/%7Esi/HXmlToolbox/hdoc_arrow/Text-XML-HXT-Arrow-XmlArrow.html#v%3AgetAttrValue">getAttrValue</a> :: String -> a <a href="http://www.fh-wedel.de/%7Esi/HXmlToolbox/hdoc_arrow/Text-XML-HXT-DOM-TypeDefs.html#t%3AXmlTree">
XmlTree</a> String<br><br>Are Arrows the wrong tool for this job?<br><br>Thanks,<br>Greg<br><br><span style="font-family: courier new,monospace;"></span><br><br><br>On 7/14/06, Greg Fitzgerald <<a href="mailto:garious@gmail.com">
garious@gmail.com</a>> wrote:<br>> <br>> I'm trying to think of a way to translate this input, to the output below:<br>> <br>> Input:<br>> <test><br>> <foo name="a"><br>> <wahoo>A</wahoo>
<br>> </foo><br>> <foo name="b"><br>> <wahoo>B</wahoo><br>> </foo><br>> <foo name="c"><br>> <wahoo>C</wahoo><br>
> </foo><br>> <group><br>> <bar ref="b"/><br>> <bar ref="a"/><br>> </group><br>> </test><br>> <br>> Output:<br>> <test>
<br>> <group><br>> <wahoo>B</wahoo><br>> <wahoo>A</wahoo><br>> </group><br>> </test><br>> <br>> That is, anywhere there is a 'bar', replace it with the contents of the 'foo' it references. I'm having a difficult time representing this with HXT's Arrow API because the value of the 'ref' attribute is the output of an arrow, but I need it to be just a plain string so that I could use it as an input parameter to the 'hasAttrValue' function. A similar problem, using 'processTopDown', once I traverse to a 'bar' node, I need to then traverse the root again to find the 'foo', but I'm in the context of the 'bar' node, not the root.
<br>> <br>> My ears are open to solutions with HaXML or Scrap Your XML-plate, or anything else.<br>> <br>> Thanks,<br>> <br>> Greg<br>> <br>> <br><br>