Assuming my last post was too hideous for anyone to take the time to attempt to comprehend, let me try to simplify:
How can I extract the input of an arrow so that I can use it as a parameter of a normal function?
How do I implement 'f' such that it can call 'g'?
f :: (ArrowXml a) => XmlTree -> a String XmlTree
g :: (ArrowXml a) => String -> a XmlTree XmlTree
Thanks,
Greg
Adding some code to go along with my last post:
main = do
[tree] <- runX (readDocument [(a_validate, "0")] " text.xml")
[fooDoc ] <- runX (constA tree >>> processChildren isFoo)
[expanded] <- runX (constA tree >>> processTopDown (expandNode fooDoc `when` hasName "bar"))
[status] <- runX (constA expanded >>> writeDocument [] "-" >>> getErrStatus)
(putStrLn . show) status
where
expandNode :: (ArrowXml a) => XmlTree -> a XmlTree XmlTree
expandNode :: (ArrowXml a) => XmlTree -> a XmlTree XmlTree
expandNode foos = this -- what here???
isFoo = deep (hasName "foo")
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):
expandNode' :: (ArrowXml a) => String -> a XmlTree XmlTree
expandNode' name = processChildren (hasAttrValue "name" name)
Somewhat related, if the output of an arrow is a string, can I get access to that string without using 'runX':
getAttrValue :: String -> a XmlTree String
Are Arrows the wrong tool for this job?
Thanks,Greg
On 7/14/06, Greg Fitzgerald < garious@gmail.com> wrote:
>
> I'm trying to think of a way to translate this input, to the output below:
>
> Input:
> <test>
> <foo name="a">
> <wahoo>A</wahoo>
> </foo>
> <foo name="b">
> <wahoo>B</wahoo>
> </foo>
> <foo name="c">
> <wahoo>C</wahoo>
> </foo>
> <group>
> <bar ref="b"/>
> <bar ref="a"/>
> </group>
> </test>
>
> Output:
> <test>
> <group>
> <wahoo>B</wahoo>
> <wahoo>A</wahoo>
> </group>
> </test>
>
> 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.
>
> My ears are open to solutions with HaXML or Scrap Your XML-plate, or anything else.
>
> Thanks,
>
> Greg
>
>