Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Update Child Nodes in Vb.net

Update Child Nodes in Vb.net

Scheduled Pinned Locked Moved Visual Basic
csharpquestionannouncementlinq
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    i i i
    wrote on last edited by
    #1

    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
    
    R 1 Reply Last reply
    0
    • I i i i

      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
      
      R Offline
      R Offline
      RobCroll
      wrote on last edited by
      #2

      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."

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups