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 class="Apple-style-span" 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">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 class="Apple-style-span" 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><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">David.</font></div></div>