Link to home
Create AccountLog in
Avatar of EfrenM
EfrenMFlag for United States of America

asked on

XML in VB .net

Hi All

i got this xml file which i need sent to textboxes. i currenlty have a piece of code that does it but
the current xml document has multiple nodes i think they are called.

is there i could do something like this
for each group
do something here
end for
<my:myFields xml:lang="en-US" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-12-29T14:17:33">
- <my:group1>
- <my:group2>
  <my:Lastname>Doe</my:Lastname> 
  <my:Firstname>John</my:Firstname> 
  <my:field3>jimmyworld</my:field3> 
  <my:field4>sub contractor</my:field4> 
  <my:field5>all_261813</my:field5> 
  <my:field6>519</my:field6> 
  <my:field7>java lama</my:field7> 
  <my:field8 /> 
  <my:field9>john@jimmyworld.com</my:field9> 
  <my:field10>@jimmie@</my:field10> 
  </my:group2>
- <my:group2>
  <my:textboxLastname>Doeye</my:textboxLastname> 
  <my:textboxFirstname>Jane</my:textboxFirstname> 
  <my:field3>janeworld</my:field3> 
  <my:field4>sub contractor</my:field4> 
  <my:field5>all_3623</my:field5> 
  <my:field6>519</my:field6> 
  <my:field7>lama java</my:field7> 
  <my:field8 /> 
  <my:field9>jane@janeworld.com</my:field9> 
  <my:field10>@jane@</my:field10> 
  </my:group2>
  </my:group1>
  <my:textboxApprover>hey@hey.com</my:textboxApprover> 
  </my:myFields>

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

You could do something like the following. Note, if you only want to handle each "group" (1 vs. 2) at a time, then you can modify the XPath in line 8 by removing/modifying the "OR" condition ( | ).
Sub Main()
    Dim xdoc As New XmlDocument()
    Dim mgr As New XmlNamespaceManager(xdoc.NameTable)

    xdoc.Load("test.xml")
    mgr.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-12-29T14:17:33")

    Dim nodes As System.Xml.XmlNodeList = xdoc.SelectNodes("//my:group1 | //my:group2", mgr)

    For Each node As System.Xml.XmlNode In nodes

    Next

  End Sub

Open in new window

Avatar of EfrenM

ASKER

what if the nodes are dynamic. meaning it can have up to 20.
also any ideas how i i can have <my:Lastname>Doe</my:Lastname>
load to lets say textbox1.text
I am confused by your requirement. If you have 20 of these nodes, and you want to load a particular element to a TextBox, you will overwrite the value in the TextBox each time you assign to the TextBox. Is this what you intend to do?
Avatar of EfrenM

ASKER

sorry for the confusion this is what i am trying to do
load the xml fields into the textboxes
so john doe would be first
then create a AD account based on the textboxes once done
load jane doe into the textboxes
then create a AD account based on the textboxes
continue if more users are on the xml form
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Here's a screenshot:
Untitled.png
Avatar of EfrenM

ASKER

worked great thanks for the help
NP. Glad to help  :)