Mrbaseball34
Programmer
Below is a snippet of one of my NAXML file.
I am using XPath to parse the nodes, however, I am having
difficulty getting this where it doesn't duplicate values.
I need to prepend the XPAth query for FuelGradeID and
FGMPositionSummary to get the correct nodes when iterating
the FGMDetail nodes. See Delphi, using MXSML, code below.
Can anyone help out with this XPath quandry?
Here is the Delphi code to parse this file:
I am using XPath to parse the nodes, however, I am having
difficulty getting this where it doesn't duplicate values.
I need to prepend the XPAth query for FuelGradeID and
FGMPositionSummary to get the correct nodes when iterating
the FGMDetail nodes. See Delphi, using MXSML, code below.
Can anyone help out with this XPath quandry?
Code:
<?xml version="1.0"?>
<NAXML-MovementReport version="3.2">
<TransmissionHeader>
<StoreLocationID>6059</StoreLocationID>
<VendorName>Gilbarco-VeederRoot</VendorName>
<VendorModelVersion>5.00.27.01A Shell Network</VendorModelVersion>
</TransmissionHeader>
<FuelGradeMovement>
<MovementHeader>
<ReportSequenceNumber>1</ReportSequenceNumber>
<PrimaryReportPeriod>2</PrimaryReportPeriod>
<SecondaryReportPeriod>0</SecondaryReportPeriod>
<BusinessDate>2006-08-25</BusinessDate>
<BeginDate>2006-08-25</BeginDate>
<BeginTime>03:38:45</BeginTime>
<EndDate>2006-08-26</EndDate>
<EndTime>03:08:19</EndTime>
</MovementHeader>
<FGMDetail>
<FuelGradeID>1</FuelGradeID>
<FuelProductID/>
<FGMNonResettableTotal>
<FuelGradeNonResettableTotalVolume>2496833.95</FuelGradeNonResettableTotalVolume>
<FuelGradeNonResettableTotalAmount>3632711.18</FuelGradeNonResettableTotalAmount>
</FGMNonResettableTotal>
<FGMPositionSummary>
<FuelPositionID>1</FuelPositionID>
<FGMSalesTotals>
<FuelGradeSalesVolume>600.87</FuelGradeSalesVolume>
<FuelGradeSalesAmount>1779.35</FuelGradeSalesAmount>
<PumpTestAmount>0</PumpTestAmount>
<PumpTestVolume>0</PumpTestVolume>
<TaxExemptSalesVolume/>
<DiscountAmount/>
<DiscountCount/>
<DispenserDiscountAmount/>
<DispenserDiscountCount/>
</FGMSalesTotals>
</FGMPositionSummary>
<FGMPositionSummary>
<FuelPositionID>2</FuelPositionID>
<FGMSalesTotals>
<FuelGradeSalesVolume>757.001</FuelGradeSalesVolume>
<FuelGradeSalesAmount>2241.9</FuelGradeSalesAmount>
<PumpTestAmount>0</PumpTestAmount>
<PumpTestVolume>0</PumpTestVolume>
<TaxExemptSalesVolume/>
<DiscountAmount/>
<DiscountCount/>
<DispenserDiscountAmount/>
<DispenserDiscountCount/>
</FGMSalesTotals>
</FGMPositionSummary>
<FGMPositionSummary>
<FuelPositionID>3</FuelPositionID>
<FGMSalesTotals>
<FuelGradeSalesVolume>689.973</FuelGradeSalesVolume>
<FuelGradeSalesAmount>2043.84</FuelGradeSalesAmount>
<PumpTestAmount>0</PumpTestAmount>
<PumpTestVolume>0</PumpTestVolume>
<TaxExemptSalesVolume/>
<DiscountAmount/>
<DiscountCount/>
<DispenserDiscountAmount/>
<DispenserDiscountCount/>
</FGMSalesTotals>
</FGMPositionSummary>
</FGMDetail>
<FGMDetail>
<FuelGradeID>2</FuelGradeID>
<FuelProductID/>
<FGMNonResettableTotal>
<FuelGradeNonResettableTotalVolume>430398.23</FuelGradeNonResettableTotalVolume>
<FuelGradeNonResettableTotalAmount>784497.06</FuelGradeNonResettableTotalAmount>
</FGMNonResettableTotal>
<FGMPositionSummary>
<FuelPositionID>1</FuelPositionID>
<FGMSalesTotals>
<FuelGradeSalesVolume>16.671</FuelGradeSalesVolume>
<FuelGradeSalesAmount>51</FuelGradeSalesAmount>
<PumpTestAmount>0</PumpTestAmount>
<PumpTestVolume>0</PumpTestVolume>
<TaxExemptSalesVolume/>
<DiscountAmount/>
<DiscountCount/>
<DispenserDiscountAmount/>
<DispenserDiscountCount/>
</FGMSalesTotals>
</FGMPositionSummary>
<FGMPositionSummary>
<FuelPositionID>2</FuelPositionID>
<FGMSalesTotals>
<FuelGradeSalesVolume>56.832</FuelGradeSalesVolume>
<FuelGradeSalesAmount>174.11</FuelGradeSalesAmount>
<PumpTestAmount>0</PumpTestAmount>
<PumpTestVolume>0</PumpTestVolume>
<TaxExemptSalesVolume/>
<DiscountAmount/>
<DiscountCount/>
<DispenserDiscountAmount/>
<DispenserDiscountCount/>
</FGMSalesTotals>
</FGMPositionSummary>
<FGMPositionSummary>
<FuelPositionID>3</FuelPositionID>
<FGMSalesTotals>
<FuelGradeSalesVolume>20.132</FuelGradeSalesVolume>
<FuelGradeSalesAmount>61.82</FuelGradeSalesAmount>
<PumpTestAmount>0</PumpTestAmount>
<PumpTestVolume>0</PumpTestVolume>
<TaxExemptSalesVolume/>
<DiscountAmount/>
<DiscountCount/>
<DispenserDiscountAmount/>
<DispenserDiscountCount/>
</FGMSalesTotals>
</FGMPositionSummary>
<FGMPositionSummary>
<FuelPositionID>4</FuelPositionID>
<FGMSalesTotals>
<FuelGradeSalesVolume>12.096</FuelGradeSalesVolume>
<FuelGradeSalesAmount>37</FuelGradeSalesAmount>
<PumpTestAmount>0</PumpTestAmount>
<PumpTestVolume>0</PumpTestVolume>
<TaxExemptSalesVolume/>
<DiscountAmount/>
<DiscountCount/>
<DispenserDiscountAmount/>
<DispenserDiscountCount/>
</FGMSalesTotals>
</FGMPositionSummary>
</FGMDetail>
</FuelGradeMovement>
</NAXML-MovementReport>
Code:
procedure LoadFGMFile;
const
_FGMSalesTotals = '//FGMSalesTotals';
var
i_fgm, i_fgmd, i_fgmps: integer;
FuelGradeMovements, FGMDetails, FGMPositionSummaries: IXMLDOMNodeList;
FuelProduct: String;
FuelPosition: Integer;
begin
FuelGradeMovements := GetNodeList(xml.documentElement, '//FuelGradeMovement');
for i_fgm := 0 to FuelGradeMovements.length - 1 do
begin
// Get list of details
{****** GetNodeList and GetNodeValue functions defined below ******}
FGMDetails := GetNodeList(FuelGradeMovements.item[i_fgm], '//FGMDetail');
// For each detail
for i_fgmd := 0 to FGMDetails.length - 1 do
begin
FuelProduct := GetNodeValue(FGMDetails.item[i_fgmd], '//FuelGradeID');
FGMPositionSummaries := GetNodeList(FGMDetails.item[i_fgmd], '//FGMPositionSummary');
for i_fgmps := 0 to FGMPositionSummaries.length - 1 do
try
FuelPosition := StringToInt(GetNodeValue(FGMPositionSummaries.item[i_fgmps],
'//FuelPositionID'));
// Post: Fuel Sale
ImportData.PostDispenser(
FuelPosition,
FuelProduct,
0,
0,
StringToFloat(GetNodeValue(FGMPositionSummaries.item[i_fgmps],
_FGMSalesTotals + '/PumpTestAmount')),
StringToFloat(GetNodeValue(FGMPositionSummaries.item[i_fgmps],
_FGMSalesTotals + '/PumpTestVolume')),
StringToFloat(GetNodeValue(FGMPositionSummaries.item[i_fgmps],
_FGMSalesTotals + '/FuelGradeSalesAmount')),
StringToFloat(GetNodeValue(FGMPositionSummaries.item[i_fgmps],
_FGMSalesTotals + '/FuelGradeSalesVolume')),
1);
except
on E: Exception do if E is EAbort then raise
else if E is EConvertError then
LogInformation(peInvalidImportData, CodeSection, lkUserError)
else
LogInformation(peSystemError, CodeSection, lkSystemError);
end;
end;
end;
end;
function GetNodeValue(Node: IXMLDOMNode; XPath: String): String; overload;
begin
try
Result := Node.selectSingleNode(XPath).text;
except
Result := ''; // Just return blank if Exception occurs
end;
end;
function GetNodeList(Node: IXMLDOMNode; XPath: String): IXMLDOMNodeList; overload;
begin
Result := Node.selectNodes(XPath);
end;
function GetNodeList(Elem: IXMLDOMElement; XPath: String): IXMLDOMNodeList; overload;
begin
Result := Elem.selectNodes(XPath);
end;