I really wouldn't use tag soup for this. Haskell has libraries specifically for XML processing which might be better suited to your needs.<br><br><div class="gmail_quote">On Fri, Dec 3, 2010 at 5:59 AM, David Virebayre <span dir="ltr"><<a href="mailto:dav.vire%2Bhaskell@gmail.com">dav.vire+haskell@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hello café, <br><br>I have seen tutorials about extracting information from a tag soup, but I have a different use case:<br>
I want to read a xml file, find a tag, change its content, and write the xml file back.<br><br>This is an example of the files<br>
<br><font face="'courier new', monospace"><?xml version="1.0" encoding="UTF-8" standalone="yes"?><br><idPkg:Story xmlns:idPkg="<a href="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" target="_blank">http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging</a>" DOMVersion="7.0"><br>
<Story Self="ub9fad" AppliedTOCStyle="n" TrackChanges="false" StoryTitle="$ID/" AppliedNamedGrid="n"><br> <StoryPreference OpticalMarginAlignment="false" OpticalMarginSize="12" FrameType="TextFrameType" StoryOrientation="Horizontal" StoryDirection="LeftToRightDirection"/><br>
<InCopyExportOption IncludeGraphicProxies="true" IncludeAllResources="false"/><br> <ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/prix"><br>
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]"><br> <Content>zzznba5</Content><br> </CharacterStyleRange><br>
</ParagraphStyleRange><br> </Story><br></idPkg:Story></font><br><br>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 ?<div>
<br><font face="'courier new', monospace">ts = do<br> soup <- parseTags `fmap` readFile "idml/h00/Stories/Story_ub9fad.xml"<br> writeFile "test" $ renderTagsOptions renderOptions{optMinimize = const True}<br>
$ modif soup<br><br>modif [] = []<br>modif (x@(TagOpen "Content" []):TagText _m : xs) = x : TagText "modified" : modif xs<br>modif (x:xs) = x : modif xs</font><br><font color="#888888"><div>
<font face="'courier new', monospace"><br>
</font></div><div><font face="arial, helvetica, sans-serif">David.</font></div></font></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div> Alex R</div></div><br>