0

Can't read two elements? I can read one element but I don't know how to read two.

&FieldL= &inXMLDoc.DocumentElement.GetElementsByTagName("ws:Name_Data");

For &a = 1 To &FieldL.Len
      &pNode = &FieldL[&a];
      &Name_Type = &pNode.GetElementsByTagName("ws:Name_Type");
      &aName_Type = &Name_Type [1].NodeValue;

   End-For;

Here is the XML file.

<ws:Name_Data>
    <ws:Name_Type>Legal</ws:Name_Type>
    <ws:First_Name></ws:First_Name>
 </ws:Name_Data>
<ws:Name_Data>
      <ws:Name_Type>Preferred</ws:Name_Type>
      <ws:First_Name></ws:First_Name> 
</ws:Name_Data>

Consider Solutions

For &a = 1 To &FieldL.Len 
&pNode = &FieldL[1];
&pNode2 = &FieldL[2];

&Name_Type = &pNode.GetElementsByTagName("ws:Name_Type");
&aName_Type = &Name_Type [1].NodeValue;
&aName_Type2 = &pNode2.GetElementsByTagName("ws:Name_Type");
&aName_Type22 = &aName_Type2 [1].NodeValue; 
End-For;
Viktor
  • 11
  • 8
  • ``` For &a = 1 To &FieldL.Len &pNode = &FieldL[1]; &pNode2 = &FieldL[2]; &Name_Type = &pNode.GetElementsByTagName("ws:Name_Type"); &aName_Type = &Name_Type [1].NodeValue; &aName_Type2 = &pNode2.GetElementsByTagName("ws:Name_Type"); &aName_Type22 = &aName_Type2 [1].NodeValue; End-For; ``` – Viktor Feb 24 '20 at 23:49

1 Answers1

0
For &a = 1 To &FieldL.Len
    [...]
    &aName_Type = &Name_Type [1].NodeValue;
End-For;

If &a = 2, the value in &aName_Type will be overwritten. Make sure &aName_Type is an array, and use the index.

For &a = 1 To &FieldL.Len
    [...]
    &aName_Type[&a] = &Name_Type[1].NodeValue;
End-For;
Based
  • 950
  • 7
  • 18
  • Your solution would require a new variable for every node in the xml file though. – Based Feb 25 '20 at 17:01
  • Thanks for your comments. I got it to work, see above comment. Also, you need to consider passing &aName_Type value into a db table. Thanks – – Viktor Feb 25 '20 at 17:05
  • @Viktor If you want people to consider something, you might want to include it in your question. My point stands, your solution doesn't scale. You'd have to declare additional variables for every additional node in the XML file. – Based Feb 27 '20 at 09:52