Filter XML data:
Let us assume that if in a real contact application, users may not want to see "email", "City", "or" Country "in the hierarchical TreeView, they may want to see the top user contact Content, such as Alex, Rebekah, or Justin, Since the corresponding details of this contact point (email, city) is in neighborly editable areas, similar users may also want to rearrange them through up and down drag trees nodes. However, it is meaningless to move email addresses through the TreeView control inside the individual contact point. People usually want to organize data with a range of views, not simply classify them, and in other words, re-order groups is normal, unless the city and country elements are associated with the specified connection. The association is very clear, and you may want to handle them separately, rather than packetize them.
A good solution is to hide the child node when the contact tree is displayed, for example, you can add a special property (such as view = "hide"), which is in the assembled tree control, such as Email. Address, etc. Set this special attribute in the assembly method, so that any element (including their child nodes) can be ignored, although this works, but changing the data source to suit the user to display is not a very reliable design idea.
A better idea is to define the structure of the hierarchical view in a given document, you can modify the populateTreeControl () method to allow it to support XPATH, for example:
[C #]
Private void PopulatetreeControl (System.xml.xmlnode Document,
System.Windows.Forms.treenodeCollection Nodes)
{
Foreach (System.xml.xmlnode Node in
Document.childNodes)
{
System.xml.xmlNode Expr =
node.selectsinglenode (xpath_filter);
IF (expr! = null)
{
Treenode New_Child = New
Treenode (expr.value);
Nodes.add (new_child);
PopulaTreeControl (Node, New_Child.nodes);
}
}
}
[Vb]
Private sub populatetreeControl (_
Byval Document as system.xml.xmlnode, _
BYVAL NODES AS
System.windows.Forms.treenodeCollection
Dim node as system.xml.xmlnode
For Each Node in Document.childNodes
DIM EXPR AS System.xml.xmlnode = _
Node.selectsinglenode (xpath_filter)
IF not (expr is nothing) THEN
Dim new_child as new treenode (expr.value)
Nodes.add (new_child)
PopulaTreeControl (node, new_child.nodes)
END IF
NEXT
End Sub
Add the following line on the class level:
[C #]
Private string xpath_filter =
@ID [Parent :: Contacts or Parent :: Contact] "; [VB]
Private XPath_filter as string = _
@ID [Parent :: Contacts or Parent :: Contact] "
You can use the results of the XPath query to decide whether to recursively call the subtitle, this query has established a rule, read "select the id attribute of any 'Contacts' or 'Contact' Element.", You can also use A exclusion rule goes to determine which data you need to reject.
Attribute :: id [NOT (Parent :: Email OR)
Parent :: City or Parent :: Country)]
This is not a universal solution, but the filter based on the parent-based relationship is much better based on unlimited nodes or attributes. When the user has sufficient editable permissions, this is an XML document. A very effective way for the basic structure. Since such a simple query is already enough, unless you need more complex operations