View Single Post
  #3 (permalink)  
Old July 28th, 2009, 02:34 AM
baseliner baseliner is offline
Authorized User
Points: 102, Level: 2
Points: 102, Level: 2 Points: 102, Level: 2 Points: 102, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Posts: 23
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Thanks Sam. As I mentioned, I was trying to exclude ALL D elements as a precursor to the end-goal of excluding based on a criterion (I think I can manage the additional predicates if I can get the ALL exclusion to work OK). But the problem I'm having is that neither "(//*)[not(self::D)]" nor "//*[not(self::D)]" is excluding all the D elements. Below is my .NET code where I execute this XPath expression to compute newNodeList (the code is trying to generate a new XML doc where all D elements are excluded; eventually I want it to generate a new XML doc based on the values of @myAttr). When I look at the value of newDoc after the AppendChild, all the D elements are still there. Maybe it's something in this code that's incorrect? Thanks!

Code:
          XmlDocument Doc = new XmlDocument();
                    Doc.LoadXml(xmlInputString);
                    XmlNodeList nodeList = Doc.SelectNodes("/A/B/C/D/@myAttr");


                    for (int i = 0; i < nodeList.Count; i++ )
                    {
                        string myVal = nodeList.Item(i).ToString();

                        XmlDocument newDoc = new XmlDocument();
                        string query = "//*[not(self::D)]";
                        
                        XmlNodeList newNodeList = Doc.SelectNodes(query);
                        newDoc.AppendChild(newDoc.ImportNode(newNodeList[0], true));
                        
                        ... more code
                     }
Reply With Quote