In some cases you will know the path, or partial path, to the node you are looking for. This is often found when you are searching a HTML file (the Document Object Model or DOM), XML file, or similar storage structure.
In that case, you can use something similar to XPATH for XML documents, or other tools for other files. With XPATH you traverse your XML through a known “path” till you find the node or nodes you are looking for. The nodes do not have to be in a specific path, just a correct relationship.
Consider an XML file which is used to track your personal inventory, like a personal library. You might have a structure that follows a format like below:
Library
Videos
Video
Video
Video
Books
Book
Book
Using this concept, you could find the first book in your list by using a path that looks like:
/Library/Books/Book[0]
This follows a specific path which makes it easy to traverse and find the appropriate book.
If you wanted to get a list of videos which had an attribute of Blue-Ray, you could use something like:
Video[@type=”Blue-Ray”]
This looks at all Video Nodes and returns those that have an attribute of “type” with a value of “Blue-Ray”.
Of course there are ways to speed up the search by using a smarter path. By narrowing the search path, we can limit the nodes that are searched and make it faster. For example, since we know that videos would only be under the video branch of our file, we wouldn’t need to look under Books for example, only under Videos.
Therefore we could simplify and speed up our search with a simple modification of:
/Library/Videos/Video[@type=”Blue-Ray”]
Of course a whole chapter could be spent on the syntax of XPATH. How it’s implemented is up to the developers of XPATH, as they are responsible for navigating the nodes of an XML file. Similar libraries can be used for searching JSON files and other tree nodes. We may have to build some by scratch, but knowing how to follow a tree structure is the first step to simplifying the search for information.
A (Known) Search Path was originally found on Access 2 Learn