[Haskell-cafe] Re: XML transformation difficulties
Greg Fitzgerald
garious at gmail.com
Fri Jul 14 20:54:32 EDT 2006
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<http://www.fh-wedel.de/%7Esi/HXmlToolbox/hdoc_arrow/Text-XML-HXT-Arrow-XmlArrow.html#v%3AgetAttrValue>::
String -> a
XmlTree<http://www.fh-wedel.de/%7Esi/HXmlToolbox/hdoc_arrow/Text-XML-HXT-DOM-TypeDefs.html#t%3AXmlTree>String
Are Arrows the wrong tool for this job?
Thanks,
Greg
On 7/14/06, Greg Fitzgerald <garious at 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20060714/e2147e06/attachment.htm
More information about the Haskell-Cafe
mailing list