Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simultaneously process two XML files with Haskell and HXT

Tags:

xml

haskell

hxt

I have two XML files that I need to parse into one record. The first document contains data for most of the record, but there is a field holds an identifier for fetching data from the second XML file, somewhat like

File 1:

<nodes>
    <node>
        <key1>value1</key1>
        <!-- etc -->
        <keyN>valueN</keyN>
        <reference>1</reference
    </node>
</nodes>

File 2:

<refs>
    <ref id="1">refValue1</ref>
    <ref id="2">refValue2</ref>
</refs>

What I would like to do is while parsing the first document, retrieving the values from the key elements, is when I extract the value of <reference>, I immediately fetch the contents of <ref id="1"> from the second file.

Since I am very new to Arrows, this is proving to be quite a challenge for me to figure out how to do. I'm able to parse the first XML file just fine, but I don't know how to pass in the second document to be used on demand.

like image 794
bheklilr Avatar asked Mar 08 '26 10:03

bheklilr


1 Answers

At phg's suggestion, I tried parsing the second XML file into a Map first, then passing it into the parser for the first XML file. A little bit of fiddling and tweaking and I got it working.

like image 137
bheklilr Avatar answered Mar 10 '26 06:03

bheklilr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!