|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionDid you ever need to find specific text inside an XML file? Or did you ever need to identify, in a set of XML files, those containing a specific text? If yes, probably you used some kind of "multiple file search" utility, or simply the operating system "Search" feature, able to locate files containing a given text string. This is obviously a suitable solution for many cases. But... what about looking for specific text appearing in specific locations of the XML structure? For example: if you need to identify XML files containing a string inside a particular attribute value and *not* somewhere else, a generic text search tool becomes useless. The simple utility presented here, named "XML Search", addresses this problem, implementing a multiple XML file search mechanism that takes care of the XML file structure. How the utility worksThe utility I wrote is very simple: given an "input" folder, it looks for XML files in that folder (and eventually subfolders), loading them - one by one - into an
Instead of an "input" folder, you can also specify a single file: in this case, the search task is limited to the given file content. The search criteria are basically identified by an XPath expression you specify in the "Node selection condition" textbox: this expression will be used to select (in each XML file) the XML nodes where the tool will look for the text string you typed in the "Find what" textbox. Some option buttons allow you to specify if the search has to be done:
You can also use the XML Search tool just to locate XML files containing specific nodes or attributes (when their value doesn't matter): to achieve this, you'll use the "Just check for node existence" option. In the XPath search condition you may want to omit the root element of the XML structure; in this case you will check the "Start from DocumentElement" checkbox. If you need a case-sensitive search, you will check the "Match case" checkbox (default search is case-insensitive on the "Find what" value, but be aware that the XPath expression is always case-sensitive). If you need to exactly look for a given value, you will check the "Match whole text" checkbox; otherwise, the "Find what" value will be searched inside the XML fragment selected by your search criteria. When the search ends, a list of matching files will be displayed:
Points of interestThe XML Search utility is very simple: it essentially puts together a recursive folder scanning with an XML DOM computation based on the For the XML fragments displaying in the bottom panel, I used the very good "XML TreeView Control" found on CodeProject: I have to thank Thomas Siepe for it. I invite you to read his article about the control.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||