Random photo
Loading...
Domains for sale
|
May 12, 2004Transforming only a part of XML documentDaniel writes about transforming a portion of XML document using XPathNavigatorReader. That's a common bad surprise for MSXML-experienced people, who used to fooNode.transformNode() method, where only fooNode and its descendants are visible in XSLT. In .NET that's different - no matter which DOM node you pass to XslTransform.Transform() method, the whole XmlDocument tree is visisble in XSLT. MSDN suggests to load the portion of XML you want to transform into a temporary XmlDocument and pass it to the transformation. Too bad. What Daniel proposes instead is to load the portion of XML to be transformed into a temporary XPathDocument instead of XmlDocument. Well, that's better, but what I'd like to ask is why do one need any temporary tree at all? It's a piece of cake to write custom XPathNavigator that would limit navigation only to a specified subtree. I did that once with XmlNodeNavigator, which represents XPathNavigator over XmlNode. Less than 10Kb of code. It's ideal solution to transform only a subtree of an XmlDocument. No temporary objects, just lightweight code between XmlDocument and XSLT that limits navigation not higher that specified node. That's perfect for XmlDocument. For XPathDocument we need another one. Or better we need generic XPathNavigatorNavigator (did we really go nuts with these XML beasts?). XPathNavigatorNavigator should allow to navigate over given XPathNavigator, but should not allow to move it outside the subtree. Comments? XPathNavigatorReader and XmlNodeNavigator are both parts of Mvp.Xml project. May 12, 2004 12:06 PM
| #XML in .NET
Comments
Joe, the answer depends on API you are using. If it's XmlDocument, you can create new element and assign comment value to its InnerXml property. Alternatively instead of commenting you can move element to another branch of the tree (e.g. deleted contacts). Posted by: Oleg Tkachenko at August 21, 2004 7:34 PMI need a help! But ... Is there a way to reenable (make this comment node became an element node again) using something else then a text editor? Thanks for any help Good name I think. Self-explaining and follows naming conventions. I wish I was such good at naming :) Posted by: Oleg Tkachenko at June 24, 2004 11:14 AMI say your updates to your classes. Cool :) It is an elegant solution, much better than loading a new XMLDocument with the outerXML of the node you want to transform. Eventhough, if you modify the stylesheet, you may also transform only a part of XML document while keeping the context, i.e. the ancestors, sibblings, ... You're definitely right Oleg. Your XmlNodeNavigator is the appropriate one to replace the sub-XmlDocument loading problem. However, I also wanted to stress (and move users to) the more performant XPathDocument for transformations. Done with documentation and almost done with tests, Daniel! Posted by: Oleg Tkachenko at May 16, 2004 1:21 PMWell, if I understand correctly, namespace navigation is simple: on each elenent node (it's only elements who can bear namespace nodes), there is a list of namespace nodes to expose - one implicit (xml namespace) and one for each namespace in effect on the element. I was refering to the namespaces mostly because of the lack of correct namspace handling examples. Because of that lack, and the underdocumentation of what the namespace-related methods (MoveToFirstNamespace/ MoveToNextNamespace/ MoveToNamespace/ GetNamespace) should expose exactly (the framework docs basically just refer to the XML specs), I am still confused what those methods should expose. And therefore I don't know for sure, but can imagine, that there might be problems with namespaces being declared outside the exposed part of the document, which should be 'transferred' to the document element of the exposed branch. But then again, it might just be my lack of understanding of how Namespaces should be handled in XPathNavigator that causes me to see problems where there are none... Posted by: Luc Cluitmans at May 13, 2004 11:41 AMYou are right about MoveToId() (the same problem exists with MoveTo()) And which namespace effects do you mean? Posted by: Oleg Tkachenko at May 13, 2004 10:40 AMI have been thinking a bit about something like your XPathNavigatorNavigator a few weeks ago (but didn't implement it yet). The only problematic function is MoveToId(). To handle it correctly, you need to check if the parent implementation moves to a node that is in the exposed tree at all. That is not too hard to get working, but will probably not be very efficient. Post a comment
Listed below are links to weblogs that reference this post:
WordML and FAQ resources from John R. Durant's WebLog
WordML and FAQ resources from John R. Durant's WebLog
re: Why You Won't See XSLT 2.0 or XPath 2.0 in the Next Version of the .NET Framework from Dare Obasanjo's WebLog
Performant XML (IV): subtree transformations without re-parsing from
Performant XML (IV): subtree transformations without re-parsing from
Performant XML (IV): subtree transformations without re-parsing from
Performant XML (IV): subtree transformations without re-parsing from
High-performance XML (IV): subtree transformations without re-parsing from
Performant XML (IV): subtree transformations without re-parsing from
Performant XML (III): subtree transformations without re-parsing from
Performant XML (III): subtree transformations without re-parsing from
High-performance XML (III): subtree transformations without re-parsing from
High-performance XML (IV): subtree transformations without re-parsing from
High-performance XML (IV): subtree transformations without re-parsing from
High-performance XML (IV): subtree transformations without re-parsing from
High-performance XML (IV): subtree transformations without re-parsing from |