How to update XPaths when adding a node

user3736648

I am writing a C# forms application, that deals with a html document. I have a List of objects, where each object has an XPath for a html node.

When adding a html node, the XPath for these above objects changes.

My question is this: How is the best way to update all XPath values, after making an addition to a document? I am currently using Html Agility Pack.

EDIT

I have tried the following in code, but am not sure if Html Agility Pack has this feature, or I may be writing my code incorrectly:

  1. Before making any changes to the HtmlDocument, create a HtmlNode object for each XPath that I have
  2. Insert the new HtmlNode

I am creating the HtmlNodes with the following code:

HtmlNode htmlNode1 = testingHtmlDocument.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[1]");
  1. Should the XPath values in each of the HtmlNodes be updated after an addition has been made to the HtmlDocument? Does XPath work this way?
  2. Other than XPath, what is the best way to identify a HtmlNode, without adding any additional data to a HtmlNode?

Thanks.

Frederick Grumieaux

If you need to update the XPaths every time, you probably use indexing. And if you need to make changes often, maybe that is not the best way to go. Maybe you can add an ID to the tags? Then you could use: "//*[@id='0123-654-97854']"

  • ID's can be generated by using GUIDs
  • If you don't want to use the default id attribute for some reason you can also go for a custom data-myapp-id="..."
  • It may also be usefull to still specify the path to the tag (without indexes) like /Tag/Node/*[@data-myapp-id='...']

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to re-shuffle data in Cassandra when adding a new node?

分類Dev

How to inform and update a client when a new record inserted in mysql database using node js and socket.io

分類Dev

Voice navigation not working after MSDKUI 2.1.1 Update when adding GuidanceManeuverMonitor

分類Dev

How to update existing model when another is created?

分類Dev

How to stop UI being locked when adding things to the UI

分類Dev

How to add Histogram constraints to Yes when altering adding columns

分類Dev

How to animate transition when adding view to hierarchy in SwiftUI

分類Dev

How to use a relative file path when adding a file to MSSQL database

分類Dev

How to avoid repeating sed commands when adding sites to Varnish?

分類Dev

How to disable backbone.js from adding /# when dialog is closed

分類Dev

How to slide the node when added to an HBox in JavaFX?

分類Dev

How to update different node child at same time firebase android

分類Dev

How can I update Node.JS through JXCore?

分類Dev

how to insert and update data into postgresql from node js using if condition

分類Dev

update an item adding an attribute in dynamodb

分類Dev

How to set type of update "In App Update" when I update the app in google play console?

分類Dev

Adding Node to Initially Null LinkedList

分類Dev

Error when adding checkbox

分類Dev

How to update @FetchRequest, when a related Entity changes in SwiftUI?

分類Dev

How to update SQL table from other table when they are on different servers

分類Dev

How to update a map but only when key already exists

分類Dev

How to update the next row of the current row when a condition is met

分類Dev

How to update package cache when using module package from ansible

分類Dev

Django: How to update related model fields when creating model

分類Dev

How to update records when many fields in Flask. Python

分類Dev

How KSQL continue consume data when update Stream?

分類Dev

How to update the text of a UILabel when the user fill in some Text Fields

分類Dev

How to update custom WebView height request when content is shrunk

分類Dev

Laravel- How to update all child when parent is changed?

Related 関連記事

  1. 1

    How to re-shuffle data in Cassandra when adding a new node?

  2. 2

    How to inform and update a client when a new record inserted in mysql database using node js and socket.io

  3. 3

    Voice navigation not working after MSDKUI 2.1.1 Update when adding GuidanceManeuverMonitor

  4. 4

    How to update existing model when another is created?

  5. 5

    How to stop UI being locked when adding things to the UI

  6. 6

    How to add Histogram constraints to Yes when altering adding columns

  7. 7

    How to animate transition when adding view to hierarchy in SwiftUI

  8. 8

    How to use a relative file path when adding a file to MSSQL database

  9. 9

    How to avoid repeating sed commands when adding sites to Varnish?

  10. 10

    How to disable backbone.js from adding /# when dialog is closed

  11. 11

    How to slide the node when added to an HBox in JavaFX?

  12. 12

    How to update different node child at same time firebase android

  13. 13

    How can I update Node.JS through JXCore?

  14. 14

    how to insert and update data into postgresql from node js using if condition

  15. 15

    update an item adding an attribute in dynamodb

  16. 16

    How to set type of update "In App Update" when I update the app in google play console?

  17. 17

    Adding Node to Initially Null LinkedList

  18. 18

    Error when adding checkbox

  19. 19

    How to update @FetchRequest, when a related Entity changes in SwiftUI?

  20. 20

    How to update SQL table from other table when they are on different servers

  21. 21

    How to update a map but only when key already exists

  22. 22

    How to update the next row of the current row when a condition is met

  23. 23

    How to update package cache when using module package from ansible

  24. 24

    Django: How to update related model fields when creating model

  25. 25

    How to update records when many fields in Flask. Python

  26. 26

    How KSQL continue consume data when update Stream?

  27. 27

    How to update the text of a UILabel when the user fill in some Text Fields

  28. 28

    How to update custom WebView height request when content is shrunk

  29. 29

    Laravel- How to update all child when parent is changed?

ホットタグ

アーカイブ