TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
david_b_mcconnell
NA
2
0
XML Validation and XPath.
Oct 20 2003 5:52 AM
Hi, I am having a problem using XPath when I validate Xml documents with a schema. Basically what happens is that an XPath query doesn't return the nodes I require if a schema is used to validate the XML. I'll try and explain it as briefly as possible here. Consider the following XML.
XML Book One
Publisher
XML Book Two
Publisher
When I execute the following code 2 nodes are returned by the XPath query and this output is produced in the debug pane; Count = 2 XML Book One XML Book Two XmlTextReader reader = new XmlTextReader(@"C:\books.xml"); XmlValidatingReader vreader = new XmlValidatingReader(reader); vreader.ValidationType = ValidationType.Schema; XPathDocument xmldoc = new System.Xml.XPath.XPathDocument(vreader); XPathNavigator nav = xmldoc.CreateNavigator(); nav.MoveToRoot(); nav.MoveToFirstChild(); XmlNamespaceManager nsMgr = new XmlNamespaceManager(nav.NameTable); nsMgr.AddNamespace( "ns" , nav.NamespaceURI ); XPathExpression xPathExpr = nav.Compile("//Publisher[. = 'Publisher']/parent::node()/Title"); xPathExpr.SetContext(nsMgr); XPathNodeIterator iterator = nav.Evaluate(xPathExpr) as XPathNodeIterator; System.Diagnostics.Debug.WriteLine("Count = " + iterator.Count.ToString()); while ( iterator.MoveNext() ) System.Diagnostics.Debug.WriteLine(iterator.Current.Value); However, if i validate the same Xml with a schema as illustrated below;
XML Book One
Publisher
XML Book Two
Publisher
The XML is validated by the schema without error but no nodes are returned by the XPath query. What is going wrong? Thanks.
Reply
Answers (
0
)
creation of web pages
Memory allocation failures