From: Oleg T. <ol...@tk...> - 2006-03-15 15:51:17
|
Yeah, that sounds a bit weird. I believe you shouldn't call to iteratorReader.MoveToContent(); here. What it should perform in a nodeslit with virtual root node? I believe what it does - it moves to the first node. But why iteratorReader.Name is still gods - god knows why :) Might be a bug. Take sources and figure out what's going on there. -- Oleg Martin Honnen wrote: > Hi there, > > I am trying to get somehow familiar with parts of the MVP XML library. > > I am having some trouble to understand how XPathIteratorReader is > supposed to work, if I use ReadInnerXml() on it I do not get the result > I expect (XML of all nodes of the iterator) but only the XML of the > first node. > > Assume example XML is alike > > <?xml version="1.0" encoding="UTF-8"?> > <gods> > <god>Kibo</god> > <!-- All for Kibology --> > <god>Xibo</god> > </gods> > > then with a normal XmlTextReader and ReadInnerXml() I can do e.g. > > XmlTextReader xmlReader = new XmlTextReader(args[0]); > xmlReader.MoveToContent(); > Console.WriteLine("Current node type: {0}, current name: {1}", > xmlReader.NodeType, xmlReader.Name); > Console.WriteLine("ReadInnerXml():\r\n{0}", xmlReader.ReadInnerXml()); > xmlReader.Close(); > > and the output is > > Current node type: Element, current name: gods > ReadInnerXml(): > > <god>Kibo</god> > <!-- All for Kibology --> > <god>Xibo</god> > > that is ReadInnerXml() in the example gives me the serialized XML of all > child nodes of the root element gods. > > Now I thought the following use of XPathNodeIterator would give the same > result: > > XPathDocument xmlDocument = new XPathDocument(args[0]); > XPathNavigator xPathNavigator = xmlDocument.CreateNavigator(); > XPathNodeIterator nodeIterator = xPathNavigator.Select(@"*/node()"); > > XPathIteratorReader iteratorReader = new > XPathIteratorReader(nodeIterator, "gods"); > iteratorReader.MoveToContent(); > Console.WriteLine("Current node type: {0}, current name: {1}", > iteratorReader.NodeType, iteratorReader.Name); > Console.WriteLine("ReadInnerXml():\r\n{0}", > iteratorReader.ReadInnerXml()); > iteratorReader.Close(); > > Result for me with .NET 1.1 and MVP XML library 1.2 is however: > > Current node type: Element, current name: gods > ReadInnerXml(): > <god>Kibo</god> > > > Is that the intended result? If the XPathIteratorReader is positioned on > the faked root element gods why does ReadInnerXml() not output the > serialized XML of all child nodes of that root element but only the > serialized XML of the first element child node? > > |