The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →For two marker elements with the same parent, select nodes that have the start marker before them and the end marker after them:
//item[preceding-sibling::start and following-sibling::end]
This is a strict-between query: it returns the matching item elements, but not start or end. The rest of the solution depends on whether the markers are siblings, whether endpoints should be included, and whether markers repeat.
Use sibling axes when both markers share a parent
preceding-sibling examines children of the current node’s parent that occur earlier in document order. following-sibling examines those that occur later. Combining both predicates therefore keeps only nodes located between the two markers.
//item[preceding-sibling::start and following-sibling::end]
Given this XML:
<section>
<start/>
<item id="a"/>
<item id="b"/>
<end/>
</section>
the expression returns the elements with IDs a and b. The markers themselves fail one of the two predicates and are excluded.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
Select every element type between the markers
Replace the element name with * when the result may contain several element names:
//*[preceding-sibling::start and following-sibling::end]
The * node test selects element nodes on the principal element axes. It does not select comments, text nodes, processing instructions, attributes, or namespace nodes.
Constrain markers by attributes
When generic marker names are not unique, put the identifying condition on the axis step:
//div[@class='entry'][preceding-sibling::h2[@id='start'] and following-sibling::h2[@id='end']]
This selects only div elements in the same parent whose preceding and following siblings include the specified headings.
Understand what the predicates mean
The predicates are evaluated with each candidate node as the context node. For a candidate to survive, both of these must be true:
preceding-sibling::startfinds at least one matchingstartsibling before the candidate.following-sibling::endfinds at least one matchingendsibling after the candidate.
This is a positional relationship, not a string search. Whitespace between elements does not matter, and the candidate does not need to be an item if you use * or another node test.
When the markers are in different branches
Sibling axes cannot cross parents. If the start and end markers are in different branches of the document, use document-order axes instead. The following axis selects nodes after the context node while excluding its descendants. The preceding axis selects nodes before the context node while excluding its ancestors.
Rank #2
- Used Book in Good Condition
XPath 1.0 intersection pattern
XPath 1.0 has no general set-intersection operator, so a practical technique is to select nodes before the second marker and retain only those also after the first marker:
(//incision[2]/preceding::*)[
count(. | (//incision[1]/following::*))
= count((//incision[1]/following::*))
]
In this example, //incision[1] is the first start marker and //incision[2] is the second marker. The outer expression starts with every element before the second marker. The count test keeps a node only when the union of that node and the first marker’s following elements has the same size as the following-elements set—evidence that the node is already in that set. Adapt the element name and occurrence numbers to your document.
XPath 2.0 and later
XPath 2.0+ implementations can use node-order comparisons or sequence operations, usually after the host language binds the intended start and end nodes. The exact syntax depends on the processor and API. Check the engine version before using a 2.0+ expression: many browser and automation interfaces still expose XPath 1.0 behavior.
Include one or both boundary elements
The strict-between expressions deliberately exclude the markers. Add a union when the result must contain an endpoint:
//start | //item[preceding-sibling::start and following-sibling::end] | //end
For only the start boundary, omit the //end branch; for only the end boundary, omit //start. Apply a positional predicate to the complete union by wrapping it in parentheses:
(//start | //item[preceding-sibling::start and following-sibling::end] | //end)[1]
Without the parentheses, [1] binds only to the final location step rather than to the combined result.
Handle repeated sections and choose the nearest markers
A bare preceding-sibling::start is true if any earlier matching sibling exists. In a document containing several sections, that can make a candidate in a later section appear to belong to an earlier start marker. Make the intended occurrence explicit or require the nearest marker on each side.
Use explicit IDs or occurrences
//item[
preceding-sibling::start[1][@id='start-1']
and following-sibling::end[1][@id='end-1']
]
The [1] on each sibling axis selects the nearest matching sibling in that direction, after which the ID condition verifies that it is the expected boundary.
For document-wide markers, select the intended occurrence before applying a between test, for example (//start)[1] and (//end)[1]. If sections can nest or overlap, decide whether you want the nearest enclosing pair, a particular numbered pair, or a flat document-order range; test that rule against representative XML because one XPath cannot infer an unstated pairing policy.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteChoose the right node test and context
Elements versus all node kinds
Use node() instead of * when comments, text nodes, or processing instructions must be returned:
/section/node()[preceding-sibling::start and following-sibling::end]
Attributes and namespace nodes are not children selected by these child-oriented tests. Query them through their own axes or from the element that owns them.
Namespaces
Namespace-qualified XML requires a namespace binding in the host API. A literal prefix in the XPath is not automatically connected to the document’s prefix. Bind the namespace URI to a prefix supported by your XPath library, then use that bound prefix in the expression. A query can otherwise return no nodes even when the serialized XML visibly contains the prefix.
Absolute and relative paths
A leading // searches descendants from the document context. A relative path starts at the current context node supplied by your parser, browser driver, or XML library. If the expression unexpectedly returns nothing, verify that the context is the document (or the intended section) and that the marker is actually within the searched subtree.
Pick an expression by situation
| Situation | Recommended pattern | Endpoint behavior | Compatibility note |
|---|---|---|---|
| Markers share a parent; candidates are one element type | //item[preceding-sibling::start and following-sibling::end] |
Excludes both | XPath 1.0-compatible |
| Markers share a parent; any element is allowed | //*[preceding-sibling::start and following-sibling::end] |
Excludes both | XPath 1.0-compatible |
| Markers are in different branches | XPath 1.0 intersection using preceding:: and following:: |
Usually excludes markers | Use occurrence-qualified markers |
| Include boundaries | Union of start, strict-between result, and end | Includes selected endpoints | Parenthesize before positional predicates |
| Repeated sections | Nearest-axis predicates such as preceding-sibling::start[1] |
Pairs with nearest or identified markers | Validate nesting and overlap rules |
| Comments or text must be returned | Use node() instead of * |
Depends on node test | Attributes need separate handling |
A reliable implementation workflow
- Inspect the tree. Confirm whether the markers have the same parent. If they do, start with sibling axes; otherwise plan a document-order query.
- Define the endpoint rule. Decide whether “between” excludes both markers or whether one or both should be returned through a union.
- Make markers unique. Add IDs, classes, names, or occurrence positions. Do not rely on an unqualified marker name when several sections exist.
- Choose the node test. Use a concrete element name for a narrow result,
*for any element, ornode()for non-element nodes. - Check the engine. Confirm whether the API implements XPath 1.0 or a later version before using intersection, sequence, or node-order features supplied by the host language.
- Test boundary cases. Try no start marker, no end marker, adjacent markers, multiple sections, nested sections, and a candidate after the final end marker.
- Inspect the returned nodes. Verify both order and count. A result that is too large usually indicates an unqualified repeated marker; an empty result commonly indicates the wrong context or namespace binding.
Troubleshooting common failures
Nodes from later sections are included
Cause: an earlier marker anywhere on the relevant axis satisfies the predicate.
Fix: constrain the nearest marker with [1], use IDs, or select explicit occurrences such as (//start)[2].
The expression returns no nodes
Cause: the markers are not siblings, the context node is wrong, or a namespace prefix is unbound.
Fix: inspect the parent relationship, switch to preceding::/following:: for different branches, and configure the namespace map in the host API.
Recommended Free Tools
The markers appear in the result
Cause: the query used a broad range or a union that intentionally included endpoints.
Fix: use the strict two-predicate form alone, or remove the endpoint branches from the union.
Only elements are returned, but text is required
Cause: * selects element nodes.
Fix: use node() and evaluate the expression from the correct parent context.
A 2.0 expression fails in a browser driver
Cause: the driver exposes XPath 1.0.
Fix: use the sibling predicates or the XPath 1.0 intersection pattern, or perform node-order filtering in the host language after selecting the two boundaries.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallBest Value
Performance and reliability considerations
Start from the narrowest context available. A section-relative path avoids scanning unrelated parts of a large document, and a specific marker attribute is cheaper to reason about than a generic name used throughout the tree. Broad expressions such as //* are useful for discovery but can return many nodes and make repeated-marker mistakes harder to see.
For document-wide ranges, resolve and validate the two boundaries once in application code when possible, then evaluate the range against that known pair. Cache neither a node position nor an occurrence number blindly: changes to the input document can shift both. Always test the exact XPath engine used in production because namespace handling, supported XPath version, and context setup are API-specific.
Or skip the browser setup
If your goal is to capture the page that contains the XPath-related content rather than automate a browser yourself, ScreenshotNeo provides a one-call screenshot API. Its cleanup steps accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server lets Claude, Cursor, or another MCP client call take_screenshot, get_page_info, and capture_pdf.
cURL
See the ScreenshotNeo documentation for all options.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo supports full-page captures with lazy images loaded, CSS-selector element capture, 12 device presets plus custom viewports, retina scale, dark mode, PDF settings, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, and an OpenAPI specification. Existing parameter names used by other screenshot APIs also work for easier migration.
The free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; every feature is available on every plan. Create a free ScreenshotNeo account.
Frequently Asked Questions
Can I pair a start marker with the next end marker only?
Yes, but state that pairing rule explicitly and enforce it with nearest-axis predicates such as preceding-sibling::start[1] and following-sibling::end[1], or bind the intended occurrences in application code.
Why does an XPath range behave differently after the XML is reformatted?
Whitespace changes normally do not affect element-axis queries. A change in parentage, namespaces, marker order, or the API’s context node can change the result.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Should I use XPath or host-language code for overlapping sections?
Use XPath for a clearly defined, non-overlapping rule. For nested or overlapping ranges, selecting the boundaries first and applying explicit node-order logic in the host language is easier to verify.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

