Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

Sending XML to A Server Via HTTP Post and parsing the received XML data II

Let's say you don't know how many <Customer> data you will receive
<Consumer>
  <PaymentMech>
    <CreditCard>
      <Expires DataType="ExpirationDate">01/04</Expires>
      <Number DataType="String">4111111111111111</Number>
    </CreditCard>
  </PaymentMech>
</Consumer>
<Consumer>
  <PaymentMech>
    <CreditCard>
      <Expires DataType="ExpirationDate">01/04</Expires>
      <Number DataType="String">4111111111111111</Number>
    </CreditCard>
  </PaymentMech>
</Consumer>
.
.
.
.
How can you get every customers credit card details and put them in stringlist?
0
bilgehanyildirim
Asked:
bilgehanyildirim
1 Solution
 
EddieShipmanCommented:
First off, if that is how it is coming over, it is not well formed and you won't be able to parse
it with the DOM. It will require a "Parent" node for the Consumer Nodes.

Kind of like this:
<CCDATA>
<Consumer>
  <PaymentMech>
    <CreditCard>
      <Expires DataType="ExpirationDate">01/04</Expires>
      <Number DataType="String">4111111111111111</Number>
    </CreditCard>
  </PaymentMech>
</Consumer>
<Consumer>
  <PaymentMech>
    <CreditCard>
      <Expires DataType="ExpirationDate">02/04</Expires>
      <Number DataType="String">4222222222222222</Number>
    </CreditCard>
  </PaymentMech>
</Consumer>
</CCDATA>

Otherwise, you will get an error when trying to lod it into the DOM.

If you are able to get the XML Well formed, you can get the data like this:

    oNodeList := oXMLDoc.selectNodes('//Consumer');
    for i := 0 to oNodeList.length-1 do
    begin
      oExpiresNode := oNodeList.item[i].firstChild;
      Memo1.Lines.Add(oExpiresNode.text);
    end;


For the XML above, the above code would place this in Memo1:
01/04 4111111111111111
02/04 4222222222222222
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now