65.9K
CodeProject is changing. Read more.
Home

XPathEditor: A Tool for Building XPath Expression Base on XML Schema

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.57/5 (9 votes)

Jul 29, 2005

CPOL

2 min read

viewsIcon

114706

downloadIcon

3105

A tool for building XPath expression base on XML Schema

Sample screenshot

Introduction

(Note: This paper is not final and needs editing. All source code is available to download.)

XPath expression is efficient filtering of XML Documents. Building XPath expression based on XML Document can be easily implemented with some tools such as Altova, Stylus.

Our application workflow designer needs to have an XPath expression based on XML Schema, so I wrote this tool. Prior to writing this tool, I just saw how the Oracle BPEL helps user create XPath based on XML schema. But it seems to be complex to use. After a month of working, the tool has been released with the following features:

  • Open an XML schema document and parse it into Tree view
  • Create location path expression from Tree view
  • Create Xpath expression with Core Function Library and basic operators
  • XPath expression syntax coloring
  • Validate an XPath expression

Preparing the Ground

The XML Path expression defines the syntax for addressing parts of an XML document. XPath expressions are evaluated against a document’s logical tree structure to identify a set of nodes (for example, elements, attributes, text, and so on).

XPath defines a tree model against which all expressions are evaluated. Most XPath expressions identify a set of nodes in the tree. For example, the following XPath expression identifies the two price elements: "/invoice/item/price".
XML Schema is an XML based alternative to DTD. It describes a model for a whole class of XML documents. Most applications of XML schema are used to validate an XML document.

You could find some tutorials here.

Short Instruction

Open the XML schema file.
When you have found the XML element or attribute for which you want to construct an XPath expression, just click and drag this node into the expression text box to get the Location path expression.
Do so if you want to use the core functions and operators.

Since the prefix of namespace has been declared in an XML schema may be different with prefix of an XML Document instance. So before trying to evaluate an XPath expression with XML document, please resolve the XML Schema namespace prefix with the XML Document namespace prefix.

History

  • 29th July, 2005: Initial post