6. September 2024 08:47
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XML_Data>
<Records>
<Record>
<Row_ID>1</Row_ID>
<First_Name>John</First_Name>
<Last_Name>Doe</Last_Name>
<Company_>ABC Corp</Company_>
<Street_Number>1234</Street_Number>
<Street_Name>Main St</Street_Name>
<Suffix_>Apt 101</Suffix_>
<City_>Springfield</City_>
<State_>IL</State_>
<Zip_>62701</Zip_>
<Area_Code>217</Area_Code>
<Phone_>5551234</Phone_>
</Record>
<Record>
<Row_ID>2</Row_ID>
<First_Name>Jane</First_Name>
<Last_Name>Smith</Last_Name>
<Company_>XYZ Inc</Company_>
<Street_Number>5678</Street_Number>
<Street_Name>Elm St</Street_Name>
<Suffix_>Suite 200</Suffix_>
<City_>Chicago</City_>
<State_>IL</State_>
<Zip_>60601</Zip_>
<Area_Code>312</Area_Code>
<Phone_>5555678</Phone_>
</Record>
<Record>
<Row_ID>3</Row_ID>
<First_Name>Emily</First_Name>
<Last_Name>Johnson</Last_Name>
<Company_>Widget Co</Company_>
<Street_Number>9101</Street_Number>
<Street_Name>Oak St</Street_Name>
<Suffix_>Ste 300</Suffix_>
<City_>Peoria</City_>
<State_>IL</State_>
<Zip_>61602</Zip_>
<Area_Code>309</Area_Code>
<Phone_>5559101</Phone_>
</Record>
</Records>
</XML_Data>
codeunit 50145 "XML Data"
{
procedure Import()
var
InS: InStream;
FileName: Text;
XmlDoc: XmlDocument;
Root: XmlElement;
Records: XmlNodeList;
Node: XmlNode;
Element: XmlElement;
ElementName: Text;
Data: record "XML Data";
Ref: RecordRef;
FieldRef: FieldRef;
i: Integer;
begin
if UploadIntoStream('Upload XML', '', '', FileName, InS) then
if XmlDocument.ReadFrom(InS, XmlDoc) then begin
XmlDoc.GetRoot(Root);
Records := Root.GetChildElements('Records');
//Message(Format(Records));
foreach Node in Records do begin
Element := Node.AsXmlElement();
// Third One
Ref.Open(DATABASE::"XML Data");
Ref.Init();
for i := 1 to Ref.FieldCount do begin
FieldRef := Ref.FieldIndex(i);
ElementName := MappingXMLToField(FieldRef.Name);
case FieldRef.Type of
FieldType::Integer:
FieldRef.Value := GetInteger(Element, ElementName);
FieldType::Text,
FieldType::Code:
FieldRef.Value := GetText(Element, ElementName);
end;
end;
Ref.Insert();
Ref.Close();
end;
end else
error('Cannot parse XML');
end;
9. September 2024 12:12
Records := Root.GetChildElements('Records')
Root.SelectNodes('Records/Record', Records)