Features
- displays the Xml-File and colorizes all matched Nodes of the tested XPath-Query.
-
Namespace-extraction from Xml-File
- Save/restore all required Informations of any tested XPath-Query:
- XmlFile, - contained XmlNamespaces, - XPath-Expression, - XmlNamespaces, which are referenced by the Expression.
- You can add a comment to each tested XPath-Query.
- some silly samples
Notice
The XPath-language is designed to specify querys from any arbitrary XmlElement. This XPath-tester only supports queries from the document-node itself.
Using the Program
- First select an Xml-File, which you want to examine.
(A click in the empty row of the selector-grid will open a FileOpenDialog.) - Then write an XPath-Expression.
- If the Expression needs to use Namespaces, you can select them from the "select Namespace" - grid.
- Caution: some (e.g. the default-) Namespaces have no prefix defined in the XmlFile. To deal with that you need to define yourself the prefix you will use in your XPath-Query (Type it into the "XPathPrefix" - Column).
- Now you can click "Markup Query-Result", and I hope, it will.
- An invalid query will beep and will markup all in red. Then pay attention to the statusbar, which displays the error-message.
- Have a backup of your successful or interesting queries by menu "Database � save".
Use of the Program
The colorizing of specified Nodes nicely shows the result of XPath-queries. That helps you to develop appropriate queries, but can also be useful to understand the function of some complicated Xml-Files (like Dataset.xsd and stuff).
E.g the screenshot shows the query-result of the XPath "//def:Compile/@Include"
, which queries all files intended to be compiled from a Project-file (*.vbproj).
The complete Sub executing that query may look like this:
Private Sub DisplayCompiledFiles(ByVal Path As String)
Dim XDoc As New XmlDocument
XDoc.Load(Path)
Dim NSMngr As New XmlNamespaceManager(XDoc.NameTable)
NSMngr.AddNamespace( _
"def", "http://schemas.microsoft.com/developer/msbuild/2003")
With New StringBuilder
For Each XAttr As XmlAttribute In XDoc.SelectNodes( _
"//def:Compile/@Include", NSMngr)
.Append(XAttr.Value).Append(ControlChars.Lf)
Next
MsgBox(.ToString)
End With
End Sub
(note: This one can be optimized with use of XPathDocument, XPathNavigator etc.)
Another point of interest is the datatype of the ForEach - iterator.
Its XmlAttribute.
Because querying "//def:Compile/@Include"
returns a XmlNodelist containing only XmlAttributes.
Querying "//def:Compile"
would return XmlElements. So the loop for that should go like:
For Each Xel As XmlElement In XDoc.SelectNodes( _
"//def:Compile", NSMngr)
.Append(Xel.GetAttribute("Include")).Append(ControlChars.Lf)
Next
Good Tutorials
about Xml and stuff
Excuse me
The program can be considered as example of blow-ware, as a result of rapid developement.
The folder "Helpers" contains a bunch of classes I often use in several projects.
So some of these classes are more powerful and complicated as (here) needed, others may look like big solutions of little problems, and again others may look like ? or ??.
Furthermore the Helper-Stuff is commented in german.
A request
Usually I'm rated very badly, and I've no idea about the reason.
IMHO a rate of 1 is appropriate to a solution that doesn't compile or else.
Please send me a mail, or give me a post to make me understand, what code-horror i've done.
thx
History
12/7/07: suggests automatically "def" as XPath-Prefix for Defaultnamespaces