[Haskell-cafe] Question about TagSoup

David Virebayre dav.vire+haskell at gmail.com
Fri Dec 3 11:59:11 CET 2010

Hello café,

I have seen tutorials about extracting information from a tag soup, but I
have a different use case:
I want to read a xml file, find a tag, change its content, and write the xml
file back.

This is an example of the files

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<idPkg:Story xmlns:idPkg="
http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="7.0">
       <Story Self="ub9fad" AppliedTOCStyle="n" TrackChanges="false"
StoryTitle="$ID/" AppliedNamedGrid="n">
               <StoryPreference OpticalMarginAlignment="false"
OpticalMarginSize="12" FrameType="TextFrameType"
StoryOrientation="Horizontal" StoryDirection="LeftToRightDirection"/>
               <InCopyExportOption IncludeGraphicProxies="true"
AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">

Assuming I want to change the content of the "Content" tag, this is what I
came up with (simplified), I'm using direct recursion. Is there a better way

ts = do
 soup <- parseTags `fmap` readFile "idml/h00/Stories/Story_ub9fad.xml"
 writeFile "test" $ renderTagsOptions renderOptions{optMinimize = const
                  $ modif soup

modif [] = []
modif (x@(TagOpen "Content" []):TagText _m : xs) = x : TagText "modified" :
modif xs
modif (x:xs) = x : modif xs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101203/b102b193/attachment.htm>

More information about the Haskell-Cafe mailing list