Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for example: Replacing a DOM element #115

Open
saurabhnanda opened this issue Oct 5, 2017 · 6 comments
Open

Request for example: Replacing a DOM element #115

saurabhnanda opened this issue Oct 5, 2017 · 6 comments

Comments

@saurabhnanda
Copy link

Can the xml-conduit family of libraries be used to replace an HTML element with another HTML element (say, the output of Lucid) and render the output? I've been struggling to figure something out from the docs, but haven't been able to do so yet.

@saurabhnanda
Copy link
Author

Just following up on this.

@k0ral
Copy link
Collaborator

k0ral commented Oct 22, 2017

Your question is a bit vague, it would be better if you could provide an example of the desired input/output and how you attempted to implement it.
From what I understand, you might want something like this:

-- Both input and output are a stream of XML events
solution :: Conduit Event m Event
solution = parseElements .| replaceElement .| renderElements

-- Implement here what you mean by "HTML element"
data Element

-- Then implement those conduits
parseElements :: Conduit Event m Element
replaceElement :: Conduit Element m Element
renderElements :: Conduit Element m Event

@saurabhnanda
Copy link
Author

saurabhnanda commented Oct 22, 2017 via email

@saurabhnanda
Copy link
Author

saurabhnanda commented Oct 22, 2017 via email

@k0ral
Copy link
Collaborator

k0ral commented Oct 30, 2017

Indeed, Text.XML.Cursor only makes it possible to browse an XML document without mutating it.
I believe you should explore the following solutions instead:

  • if the location of the element(s) to replace is known in advance (statically), then zippers or lenses are probably the right tools;
  • otherwise, you're bound to scan the whole XML document, in which case a streaming solution is relevant, and you might want to dig my previous answer.

@kindaro
Copy link

kindaro commented Dec 1, 2017

Actually, what's stopping an Axis from trying to modify a Cursor in a specified way and returning a singleton if successfully done so? It seems to me that a "replace" axis that swaps the current node of a cursor for a given one is a natural thing to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants