Update Child Nodes in Vb.net
-
Thanks in advance, I want to Update child nodes of a node, like in my XML document i have a node "Name", i want that it will search for its child Node "First_Name" having inner text "FN2" and then will update its Parents other child nodes like "Middle_Name" and "Last_Name". I had asked this Question Here www.codeproject.com/Questions/305565/how-to-Update-more-then-one-child-nodes-in-vb-net[^] and got answer to obtain this Using LINQ , is there any other way to do this Xml File
<?xml version="1.0"?>
<Names>
<Name>
<First_Name>FN 1</First_Name>
<Middle_Name>MN 1</Middle_Name>
<Last_Name>LN 1</Last_Name>
<Country_Code>001</Country_Code>
<Area_Code>
</Area_Code>
<Phone_No>
</Phone_No>
<Email_Address>mail@email.com</Email_Address>
<Address>Address 1</Address>
</Name>
<Name ID="2">
<First_Name>FN2</First_Name>
<Middle_Name>Mn2</Middle_Name>
<Last_Name>Ln2</Last_Name>
<Country_Code>02</Country_Code>
<Area_Code>002</Area_Code>
<Phone_No>0002</Phone_No>
<Email_Address>email@mail2.com</Email_Address>
<Address>
</Address>
</Name>
</Names>Code:
Function Edit() As Boolean
Try
'Dim xd As New XmlDocument()
'xd.Load(App_Path)
'Dim nod As XmlNodeList = xd.SelectNodes("//First_Name[. = '" & txtFName.Text & "']" & "/parent::node()/First_Name")'If nod IsNot Nothing Then ' For Each node In nod ' 'nod.Item(0).ChildNodes(0).InnerText = txtMName.Text.Trim ' 'nod.Item(0).ChildNodes(1).InnerText = txtLName.Text.Trim ' Next 'End If Dim xd As New XmlDocument() xd.Load(App\_Path) Dim nod As XmlNode = xd.SelectSingleNode("//First\_Name\[. = '" & txtFName.Text & "'\]" & "/parent::node()/First\_Name") If nod IsNot Nothing
-
Thanks in advance, I want to Update child nodes of a node, like in my XML document i have a node "Name", i want that it will search for its child Node "First_Name" having inner text "FN2" and then will update its Parents other child nodes like "Middle_Name" and "Last_Name". I had asked this Question Here www.codeproject.com/Questions/305565/how-to-Update-more-then-one-child-nodes-in-vb-net[^] and got answer to obtain this Using LINQ , is there any other way to do this Xml File
<?xml version="1.0"?>
<Names>
<Name>
<First_Name>FN 1</First_Name>
<Middle_Name>MN 1</Middle_Name>
<Last_Name>LN 1</Last_Name>
<Country_Code>001</Country_Code>
<Area_Code>
</Area_Code>
<Phone_No>
</Phone_No>
<Email_Address>mail@email.com</Email_Address>
<Address>Address 1</Address>
</Name>
<Name ID="2">
<First_Name>FN2</First_Name>
<Middle_Name>Mn2</Middle_Name>
<Last_Name>Ln2</Last_Name>
<Country_Code>02</Country_Code>
<Area_Code>002</Area_Code>
<Phone_No>0002</Phone_No>
<Email_Address>email@mail2.com</Email_Address>
<Address>
</Address>
</Name>
</Names>Code:
Function Edit() As Boolean
Try
'Dim xd As New XmlDocument()
'xd.Load(App_Path)
'Dim nod As XmlNodeList = xd.SelectNodes("//First_Name[. = '" & txtFName.Text & "']" & "/parent::node()/First_Name")'If nod IsNot Nothing Then ' For Each node In nod ' 'nod.Item(0).ChildNodes(0).InnerText = txtMName.Text.Trim ' 'nod.Item(0).ChildNodes(1).InnerText = txtLName.Text.Trim ' Next 'End If Dim xd As New XmlDocument() xd.Load(App\_Path) Dim nod As XmlNode = xd.SelectSingleNode("//First\_Name\[. = '" & txtFName.Text & "'\]" & "/parent::node()/First\_Name") If nod IsNot Nothing
Use SelectNodes instead of the SelectSingleNode method to return a collection of nodes. See the MSDN Article Select Nodes Using XPath Navigation for more info. The alternative to to create an XSLT
"You get that on the big jobs."