Link to home
Start Free TrialLog in
Avatar of Eddie Shipman
Eddie ShipmanFlag for United States of America

asked on

TXMLDocument Pain...

Having never messed with the TXMLDocument object before, personally I  think it is a piece of junk, I am running into a problem.
I am very well versed in using MSXML but this stuff is so foreign and feels dumb.

I am trying to write an overloaded function to return a IDOMNodeList using XPath when passed either an IDOMNode or an
IDOMElement:

function GetNodeList(Node: IDOMNode; XPath: String): IDOMNodeList; overload;
begin
  Result := (Node as IDOMNodeSelect).selectNodes(XPath);
end;

function GetNodeList(Elem: IDOMElement; XPath: String): IDOMNodeList; overload;
begin
  Result := (Elem as IDOMNodeSelect).selectNodes(XPath);
end;

I need to return the nodes according to this call:
list := GetNodeList(xml.DOMDocument.documentElement, '//JournalReport');

However, it is always returning an empty list. Any ideas?

I've tried these with the same result:

list := GetNodeList(xml.DOMDocument.documentElement.FirstChild, '//JournalReport');
list := GetNodeList(xml.DOMDocument.documentElement.ParentNode, '//JournalReport');

here is a snippet of the XML trying to parse:

<?xml version="1.0" encoding="utf-8"?>
<NAXML-POSJournal version="3.4">
  <TransmissionHeader>
    <snipped other nodes and values>
  </TransmissionHeader>
  <JournalReport>
    <JournalHeader>
      <snipped other nodes and values>
    </JournalHeader>
    <SaleEvent>
      <snipped other nodes and values>
      <TransactionDetailGroup>
        <TransactionLine>
          <snipped other nodes and values>
          <TenderInfo>
            <Tender>
              <TenderCode/>
              <TenderSubCode/>
            </Tender>
            <TenderAmount/>
            <ChangeFlag/>
          </TenderInfo>
        </TransactionLine>
      </TransactionDetailGroup>
      <TransactionSummary>
        <snipped other nodes and values>
      </TransactionSummary>
    </SaleEvent>
  </JournalReport>
</NAXML-POSJournal>

This functionality MUST also work on an earlier VERSION of the XML file formatted like this:
{Note the differences in the Tender(3.2) and TenderInfo(3.4) nodes}

<?xml-version ="1.0" standalone="no"?>
  <NAXML-POSJournal version="3.2">
    <TransmissionHeader>
      <snipped other nodes and values>
    </TransmissionHeader>
    <JournalReport>
      <JournalHeader>
        <snipped other nodes and values>
      </JournalHeader>
      <SaleEvent>
        <snipped other nodes and values>
        <TransactionDetailGroup>
          <TransactionLine>
            <snipped other nodes and values>
            <Tender>
              <TenderCode/>
              <TenderSubCode/>
              <TenderAmount/>
              <ChangeFlag/>
            </Tender>
           </TransactionLine>
          </TransactionLine>
        </TransactionDetailGroup>
      <TransactionSummary>
        <snipped other nodes and values>
      </TransactionSummary>
    </SaleEvent>
  </JournalReport>
</NAXML-POSJournal>
Avatar of mokule
mokule
Flag of Poland image

This code works for me.
After I've changed
     <snipped other nodes and values>
to
     <snippedothernodesandvalues/>


procedure TForm1.Button1Click(Sender: TObject);
var
  list: IDOMNodeList;
begin
  XMLDocument1.Active := False;
  XMLDocument1.FileName := 'test.xml';
  XMLDocument1.Active := True;
  list := GetNodeList(XMLDocument1.DOMDocument.documentElement, '//JournalReport');
  Memo1.Lines.Add(list.item[0].firstChild.nodeName);
  list := GetNodeList(XMLDocument1.DOMDocument.documentElement.ParentNode, '//JournalReport');
  Memo1.Lines.Add(list.item[0].firstChild.nodeName);
end;
Avatar of Eddie Shipman

ASKER

I still get AV's using both those methods on my document.
Here, I'll post the entire 3.4 XML for you to try...
Seems the xmlns is causing the problem.
Any way around that?

<?xml version="1.0" encoding="utf-8"?>
<NAXML-POSJournal xmlns="http://www.naxml.org/POSBO/Vocabulary/2003-10-16" version="3.4" release="3.4.0">
  <TransmissionHeader>
   <StoreLocationID>6059</StoreLocationID>
   <VendorName>Gilbarco-VeederRoot</VendorName>
   <VendorModelVersion>5.00.27.01A  Shell Network</VendorModelVersion>
  </TransmissionHeader>
  <JournalReport>
    <JournalHeader>
      <ReportSequenceNumber/>
      <PrimaryReportPeriod>2</PrimaryReportPeriod>
      <SecondaryReportPeriod>0</SecondaryReportPeriod>
      <BeginDate>2006-08-25</BeginDate>
      <BeginTime>03:38:45</BeginTime>
      <EndDate>2100-01-01</EndDate>
      <EndTime>00:00:00</EndTime>
    </JournalHeader>
    <SaleEvent>
      <TrainingModeFlag value="No"/>
      <CashierID>9</CashierID>
      <RegisterID>1</RegisterID>
      <TillID>000000000147</TillID>
      <OutsideSalesFlag value="No"/>
      <TransactionID>2587</TransactionID>
      <EventStartDate>2006-08-26</EventStartDate>
      <EventStartTime>02:56:22</EventStartTime>
      <EventEndDate>2006-08-26</EventEndDate>
      <EventEndTime>02:56:31</EventEndTime>
      <ReceiptDate/>
      <ReceiptTime/>
      <BusinessDate>2006-08-25</BusinessDate>
      <OfflineFlag value="No"/>
      <SuspendFlag value="No"/>
      <TransactionDetailGroup>
        <TransactionLine status="Normal">
          <ItemLine>
            <ItemCode>
              <POSCodeFormat format="gtin"/>
              <POSCode>02820000869</POSCode>
              <POSCodeModifier name="">0</POSCodeModifier>
            </ItemCode>
            <ItemID>028200008695</ItemID>
            <Description>Marlboro Light Box</Description>
            <EntryMethod>Scan</EntryMethod>
            <ActualSalesPrice>3.31</ActualSalesPrice>
            <UnitCostPrice/>
            <MerchandiseCode>18</MerchandiseCode>
            <SellingUnits>1</SellingUnits>
            <Discount>
              <DiscountAmount>0</DiscountAmount>
              <ReasonCode/>
            </Discount>
            <RegularSellPrice>3.31</RegularSellPrice>
            <SalesQuantity>1</SalesQuantity>
            <SalesAmount>3.31</SalesAmount>
          </ItemLine>
        </TransactionLine>
        <TransactionLine status="Normal">
          <TenderInfo>
            <Tender>
              <TenderCode>1</TenderCode>
              <TenderSubCode/>
            </Tender>
            <TenderAmount>4</TenderAmount>
            <ChangeFlag value="No"/>
          </TenderInfo>
        </TransactionLine>
        <TransactionLine status="Normal">
          <TenderInfo>
            <Tender>
              <TenderCode>1</TenderCode>
              <TenderSubCode/>
            </Tender>
            <TenderAmount>-.51</TenderAmount>
            <ChangeFlag value="Yes"/>
          </TenderInfo>
        </TransactionLine>
        <TransactionLine status="normal">
          <TransactionTax>
            <TaxLevelID>101</TaxLevelID>
            <TaxableSalesAmount>3.31</TaxableSalesAmount>
            <TaxCollectedAmount>.18</TaxCollectedAmount>
          </TransactionTax>
        </TransactionLine>
      </TransactionDetailGroup>
      <TransactionSummary>
        <TransactionTotalGrossAmount>3.31</TransactionTotalGrossAmount>
        <TransactionTotalNetAmount>3.48</TransactionTotalNetAmount>
        <TransactionTotalTaxSalesAmount>.18</TransactionTotalTaxSalesAmount>
        <TransactionTotalTaxNetAmount>.18</TransactionTotalTaxNetAmount>
        <TransactionTotalGrandAmount direction="Collected">3.49</TransactionTotalGrandAmount>
      </TransactionSummary>
    </SaleEvent>
  </JournalReport>
</NAXML-POSJournal>
ASKER CERTIFIED SOLUTION
Avatar of mokule
mokule
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, I do know that the URL in the value is not valid.
Converting the entire TXMLDocument stuff in our app to use straight MSXML.
This TXMLDocument thing is crap!