How to Parse XML
In this article, we'll explain about XML parsing. We'll start by defining XML files, their format and how to navigate them for data extraction.
To select an element that is between two known elements in XPath we have several options. Let's see these few interactive examples:
preceding-sibling
or following-sibling
:Above we select all <p>
elements that have the first preceding <h2>
element with text anchor
.
count()
:Here, we select all <p>
elements that have exactly one preceding <h2>
element. Element counting is less reliable than using an anchor element but is often much easier to implement.
XPath provides a lot of flexibility in selecting elements as we can navigate the HTML tree in every direction and match elements by any attribute.
For more on XPath, see our XPath introduction tutorial
This knowledgebase is provided by Scrapfly data APIs, check us out! 👇