Options

XML get elements with same name

helderhelder Member Posts: 2
edited 2016-10-19 in NAV Tips & Tricks
In CAL NAV2013, I want to get all elements with the same name (in this case codMsg and txtMsg). At the moment I'm trying only with the codMsg.

Example XML nodes:
<alerta>
	<actCount>
		<num>0001</num>
		<tipo>3</tipo>
	</actCount>
	<codMsg>ae11</codMsg>
	<txtMsg>description11</txtMsg>
	<codMsg>ae12</codMsg>
	<txtMsg>description12</txtMsg>
	<codMsg>ae13</codMsg>
	<txtMsg>description13</txtMsg>
	<codMsg>ae14</codMsg>
	<txtMsg>description14</txtMsg>
</alerta>
<alerta>
	<actCount>
		<num>0002</num>
		<tipo>3</tipo>
	</actCount>
	<codMsg>ae21</codMsg>
	<txtMsg>description21</txtMsg>
	<codMsg>ae22</codMsg>
	<txtMsg>description22</txtMsg>
	<codMsg>ae23</codMsg>
	<txtMsg>description3</txtMsg>
	<codMsg>ae24</codMsg>
	<txtMsg>description24</txtMsg>
</alerta>


I have tried:

1) itemsAlert.Item(i).SelectSingleNode('codMsg'), this way I only have the first element (codMsg) of each alert node.

2)
itemsAlertNode := itemsAlert.Item(i).SelectNodes('codMsg');

    IF itemsAlertNode.Count > 0 THEN BEGIN
      FOR j := 0 TO itemsAlertNode.Count - 1 DO
      BEGIN
        //title_codMsg := itemsAlertNode.Item(j).SelectSingleNode('/'); - no error, but doesn't get the content of element 
        //title_codMsg := itemsAlertNode.Item(j).SelectSingleNode('codMsg'); - error at: title_codMsgTxt := title_codMsg.InnerText, because title_codMsg is uninitialized
        //title_codMsg := itemsAlertNode.Item(j).SelectSingleNode(''); - Expression must evaluate to a node-list

        title_codMsgTxt := title_codMsg.InnerText;
      END;
    END;


How to access to: ae12; ae13; ae14...

With this "itemsAlertNode := itemsAlert.Item(i).SelectNodes('codMsg');" I see a System.XML.XPathNodeList, but I don't know if the content is what I want. Is there some way to view the content by debugging?

This is the first time I'm programming...

Thanks :)

Answers

  • Options
    helderhelder Member Posts: 2
    I found the error....

    The solution is use only: title_codMsg := itemsAlertNode.Item(j);
Sign In or Register to comment.