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?
bilgehanyildirimAsked:
Who is Participating?
 
Eddie ShipmanConnect With a Mentor All-around developerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.