Methods for Working with DOM
Creating New Block
When working with content extracted from JS, very often it is required to convert JSON data into XML. After this operation you will have XML in the register and to traverse DOM of this XML you need to convert it to the block first. To do it you need to use to_block. This command does not have any parameters, it simply takes content from the register, creates a block context from it and switch into it.
Let's use following HTML source:
- find: path: p do: - parse # REGISTER VALUE: sometext - register_set: <div>another text</div> - to_block - find: path: div do: - parse # REGISTER VALUE: another text # PLEASE NOTE, IF YOU DO `parse` NOW - parse # IN THE REGISTER YOU WILL HAVE: another text # NO MATTER WHAT WAS IN ORIGINAL `p`, AS CONTEXT WAS REPLACED WITH NEW BLOCK CONTEXT IN THIS SCOPE
In the next chapter, you will learn how to execute a part of the digger logic depending on the conditions.