Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6371287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:02:34+00:00 2026-05-25T01:02:34+00:00

I want to read HTML from a String, process it and return the changed

  • 0

I want to read HTML from a String, process it and return the changed document as a String using HXT. As this operation does not require IO, I would rather execute the Arrow with runLA than with runX.

The code look like this (omitting the processing for simplicity):

runLA (hread >>> writeDocumentToString [withOutputHTML, withIndent yes]) html

However, the surrounding html tag is missing in the result:

["\n  <head>\n    <title>Bogus</title>\n  </head>\n  <body>\n        Some trivial bogus text.\n    </body>\n",""]

When I use runX instead like this:

runX (readString [] html >>> writeDocumentToString [withOutputHTML, withIndent yes])

I get the expected result:

["<html>\n  <head>\n    <title>Bogus</title>\n  </head>\n  <body>\n        Some trivial bogus text.\n    </body>\n</html>\n"]

Why is that, and how can I fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:02:35+00:00Added an answer on May 25, 2026 at 1:02 am

    If you look at the XmlTrees for both, you’ll see that readString adds a top-level "/" element. For the non-IO runLA version:

    > putStr . formatTree show . head $ runLA xread html
    ---XTag "html" []
       |
       +---XText "\n  "
       |
       +---XTag "head" []
       ...
    

    And with runX:

    > putStr . formatTree show . head =<< runX (readString [] html)
    ---XTag "/" [NTree (XAttr "transfer-Status") [NTree (XText "200")...
       |
       +---XTag "html" []
           |
           +---XText "\n  "
           |
           +---XTag "head" []
           ...
    

    writeDocumentToString uses getChildren to strip off this root element.

    One easy way around this is to use something like selem to wrap the output of xread in a similar root element, in order to make it look like the kind of input writeDocumentToString expects:

    > runLA (selem "/" [xread] >>> writeDocumentToString [withOutputHTML, withIndent yes]) html
    ["<html>\n  <head>\n    <title>Bogus</title>\n  </head>\n  <body>\n        Some trivial bogus text.\n    </body>\n</html>\n"]
    

    This produces the desired output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse with XmlSlurper a HTML document which I read using HTTPBuilder.
I want to read the file path from html input type=file (the entry selected
I want to read and write from serial using events/interrupts. Currently, I have it
I just simply want to return a JSON object (using ajax) from my server
Please note: I do not want to read the HTML content of a page,
I have some text content (read in from the HTML using jQuery) that looks
I want to read the html file.And for that I use System.IO.File.ReadAllText(path) .It can
I want to ask how can someone read keystrokes while in a html page
I want to read line n1->n2 from file foo.c into the current buffer. I
I want to develope upload and download file from server. Upload.html <form action=/UploadFile/UploadFile method=POST

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.