I have a DOM tree (xmlCOA).
It is associated with a TreeView (TreeView1).
I would like to add a new node to the DOM tree.
After I construct the new node, I locate a particular node for adding the new node as its child.
I use "fullPath" to construct the xpath to locate the targeted node.
But, I don't understand something: the fullPath return: #document/.......
Should I trim the "#document" away?
No matter I cut it or not, it causes error: wrong xpath expression.
Why?
visual basic code:--------------------------------------------------------------------------------
VB Code:
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click 'construct the new node Dim newNode As xmlFile.XmlNode = _ xmlCOA.CreateNode(Xml.XmlNodeType.Element, "", txtElementName.Text, "") newNode.InnerText() = txtItemName.Text 'construct the xpath Dim txt As String = TreeView1.SelectedNode.Text Dim fullPath As String = TreeView1.SelectedNode.FullPath 'return value is: #document/....... fullPath = fullPath.substring(9) 'cut "#document" 'this is valid, but it cannot locate the exact node 'Dim xn As xmlFile.XmlNode = xmlCOA.SelectSingleNode("//" + txt) 'error: xpath is not valid Dim xn As xmlFile.XmlNode = xmlCOA.SelectSingleNode(fullpath) xn.AppendChild(newNode) End Sub




Reply With Quote