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

How to replace Node innerHTML and save it to new string? #22

Open
TangMonk opened this issue Nov 24, 2019 · 4 comments
Open

How to replace Node innerHTML and save it to new string? #22

TangMonk opened this issue Nov 24, 2019 · 4 comments

Comments

@TangMonk
Copy link

TangMonk commented Nov 24, 2019

Is it able to replace node innerHTML, like this:

for node in process(everydayHtmlString, '//table[@id="zhuye" or @id="fuye"]') do
  begin
    if node.toNode.getAttribute('id') = 'zhuye' then
    begin
         node.toNode.innerHTML := aStringContainHTML;
    end;
  end;

and what is the proper way to update everydayHtmlString variable to the latest?

@TangMonk TangMonk changed the title How to replace Node innerHTML? How to replace Node innerHTML and save it to new string? Nov 24, 2019
@benibela
Copy link
Owner

No, once the document is created, it cannot be changed anymore.

The you can use the transform function in xquery to create a new document (needs xquery_json in uses)

process(everydayHtmlString, ' x:transform(., function($node) { if ($node/self::table[@id="zhuye"]) then <table>aStringContainHTML</table> else $node }  )  ');

@TangMonk
Copy link
Author

TangMonk commented Dec 17, 2019

@benibela how about add a setInnerHTML method for Node? It is more convient

@TangMonk
Copy link
Author

I am used Winform in C#, there is a libaray called Html Agility Pack, It is really convient and easy to use for parse a web page

@benibela
Copy link
Owner

I do not want people to believe they can change individual nodes. Then they might try multithreading, change different nodes in different threads and the program fails because you can only modify the entire document.

Every node has an index, first node might be 10, second node 20, third node 33, ...

If you add a node, it needs to update all the node indices afterwards.

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

2 participants