Mvp.Xml Library: XPointer.NET module

The XPointer.NET module provides an implementation of the XPointer Framework Recommendation written in C# for the .NET platform. XPointer.NET supports XPointer element() Scheme, XPointer xmlns() Scheme, XPointer xpath1() Scheme and XPointer xpointer() Scheme (XPath subset only). XPointer.NET was designed and implemented for the XInclude.NET module, but it can be used on its own.

For more info about XPointer see References.

1. Usage

XPointerReader class, found in the Mvp.Xml.XPointer namespace, is the key class. It's customized XmlReader, which implements XPointer Framework, XPointer element() Scheme, XPointer xmlns() Scheme, The XPointer xpath1() Scheme and XPointer xpointer() Scheme (XPath subset only) in a caching forward-only fashion.

Usage samples:

1. Basic identifying of subresources using XPointer:
XPointerReader r =
    new XPointerReader("books.xml", "xpointer(//book)");          
while (r.Read())
    Console.WriteLine(r.ReadOuterXml());
r.Close();


2. Running XPointerReader on an in-memory XML store:

XPathDocument doc = new XPathDocument("books.xml");
XPointerReader r =
    new XPointerReader(doc, "xpointer(//book)");          
while (r.Read())
    Console.WriteLine(r.ReadOuterXml());
r.Close();


or

XmlDocument doc = new XmlDocument();
doc.Load("books.xml");
XPointerReader r =
    new XPointerReader(doc, "xpointer(//book)");          
while (r.Read())
    Console.WriteLine(r.ReadOuterXml());
r.Close();


3. When running XPointerReader on XPathDocument or XmlDocument, you can get underlying XPathNavigator via IHasXPathNavigator interface:

XPathNavigator nav = ((IHasXPathNavigator)reader).GetNavigator();


4. Namespace-aware XPointers:

XPointerReader r =
    new XPointerReader("books.xml", "xmlns(bk=http://books.com)xpointer(//bk:book)");


5. Fallback-like XPointers. Recall that XPointer can consist of a several pointer parts, which are evaluated in turn until one identifies any subresource. That property can be used to create more reliable XPointers:

XPointerReader r =
    new XPointerReader("books.xml", "element(bk101)xpointer(//book[@id='bk101'])"); 

2. Conformance

Only XPath subset of the XPointer xpointer() Scheme is currently supported.

3. Support

You can get support using the following options:

4. References

  1. "Combining XML Documents with XInclude" by Oleg Tkachenko, MSDN
  2. XPointer Framework Recommendation
  3. XPointer element() Scheme
  4. XPointer xmlns() Scheme
  5. XPointer xpointer() Scheme
  6. nxslt.exe - XInclude/XPointer enabled command line XSLT utility
  7. eXml - XInclude/XPointer enabled XML ASP.NET Web Server control

Last edited Jul 3, 2007 at 6:57 AM by olegt, version 2

Comments

No comments yet.