<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope> <soap:Body> <GetMovementResponse> <GetMovementResult> <Code>1</Code> <Message/> <Data></Data> <List> <Movement> <--- From here <Code>XXX</Code> <MovementType>XXX</MovementType> <DateMovement>2020-11-27T15:04:04.09</DateMovement> <OriginCompany> <ID>0</ID> </OriginCompany> <CenterCostSource> <ID>0</ID> <ExternalCode>1</ExternalCode> </CenterCostSource> . . . </Movement> +<Movement> +<Movement> . . .
if XmlDocument.ReadFrom(InStr, xmlDoc) then begin xmlnsMgr.AddNamespace('ns', 'http://www.company.com.br/Company'); if xmlDoc.SelectNodes('//ns:Movement', xmlnsMgr, xmlNodList) then begin foreach xmlNod in xmlNodList do begin xmlNod.SelectSingleNode('ns:OriginCompany/ns:ID', xmlnsMgr, xmlNod2); Message(xmlNod2.AsXmlElement().InnerText); end; end; end;
xmlnsMgr: XmlNamespaceManager;
Answers
How you already have the xml in a Instream, you can do something like this to get, by example, the value of OriginCompany/ID of every Movement
Where the variables are:
Regards
I tried your method but unfortunately it doesn't access the line:
I skipped that line and it shows me the following error:
Microsoft.Dynamics.Nav.Runtime.NavXmlNode variable not initialized.
I do not know if it is related to the fact that I did not enter the mentioned line
Could you elaborate what means "it doesn't access the line"
Regards.
What I mean, at runtime it doesn't execute the "foreach" block, so it skips these lines:
Then the problem is in the previous line, that is not selecting any node.
Could you post a reduced version of the XML file that you are reading ?
Regards
I had contemplated it and tried this procedure. However, it does not fill the table correctly
I only consider three fields but this process does not fill them correctly
This is just an extract, the XML contains many more nodes called "Movimentacao"
With this XML you need to use a name space manager to deal with the lien in green in the image.
And this is the new var:
Regards
I applied the example and that solves the problem. Thank you.
Could you post how are you trying to insert the data in the BC table ?
Regards.
I use the code below to import data from Azure blob storage into Customer table and Ship to Address Table
procedure ReadXML(InStr: InStream)
var
Customer: Record Customer;
ShiptoAddress: Record "Ship-to Address";
xmlDoc: XmlDocument;
CustomerTab: XmlElement;
NodeList: XmlNodeList;
NodeCustomerList: XmlNodeList;
Node: XmlNode;
XmlCustomerNode: XmlNode;
XmlShipToNode: XmlNode;
XmlCustomerElement: XmlElement;
XmlShipToElement: XmlElement;
begin
if XmlDocument.ReadFrom(InStr, xmlDoc) then begin
//Find the root element
if xmlDoc.GetRoot(CustomerTab) then
NodeList := CustomerTab.GetChildElements();
foreach Node in NodeList do begin
XmlCustomerElement := Node.AsXmlElement();
NodeCustomerList := XmlCustomerElement.GetChildElements();
foreach XmlCustomerNode in NodeCustomerList do begin
case XmlCustomerNode.AsXmlElement().Name of
'No.':
Customer.Validate(Customer."No.", XmlCustomerNode.AsXmlElement().InnerText);
'Name':
Customer.Validate(Customer.Name, XmlCustomerNode.AsXmlElement().InnerText);
'Address':
Customer.Validate(Customer.Address, XmlCustomerNode.AsXmlElement().InnerText);
'ShipToAddress':
begin
XmlShipToElement := XmlCustomerNode.AsXmlElement();
ShiptoAddress.Init();
ShiptoAddress.Validate("Customer No.", Customer."No.");
foreach XmlShipToNode in XmlShipToElement.GetChildElements() do begin
case XmlShipToNode.AsXmlElement().Name of
'Code':
ShiptoAddress.Code := XmlShipToNode.AsXmlElement().InnerText;
'ShipName':
ShiptoAddress.Name := XmlShipToNode.AsXmlElement().InnerText;
'PostCode':
ShiptoAddress.Validate("Post Code", XmlShipToNode.AsXmlElement().InnerText);
'Country':
ShiptoAddress.Validate("Country/Region Code", XmlShipToNode.AsXmlElement().InnerText);
end;
if not ShiptoAddress.Insert() then
ShiptoAddress.Modify();
end;
end;
end;
if not Customer.Insert() then
Customer.Modify();
end;
end;
end;
end;