Jump to content
Sign in to follow this  
Tommi Prami

Troubled relationship with m$Xml

Recommended Posts

If got an code :

 

uses
  Winapi.msxml, Winapi.MSXMLIntf;

procedure TForm10.Button1Click(Sender: TObject);
var
  LDocument: IXMLDomDocument3;
  LCurrrentValueNode: IXMLDOMNode;
  LNodeList: IXMLDOMNodeList;
  I: Integer;
begin
  LDocument := CoDOMDocument60.Create;
  LDocument.async := False;
  LDocument.validateOnParse := False;
  LDocument.ResolveExternals := False;
  LDocument.PreserveWhiteSpace := True;

  LDocument.loadXML(Memo1.Lines.Text);
  if LDocument.parseError.errorCode <> 0 then
    raise Exception.CreateFmt('XML parsing error : %s at row %d position %d',
      [LDocument.parseError.reason, LDocument.parseError.Line, LDocument.parseError.linepos]);

  if Assigned(LDocument.documentElement) then
    LNodeList := LDocument.documentElement.getElementsByTagName('IBAN')
  else
    LNodeList := LDocument.getElementsByTagName('IBAN');

  for I := 0 to LNodeList.Length - 1 do
  begin
    LCurrrentValueNode := LNodeList.Item[I];
    Memo2.Lines.Add(LCurrrentValueNode.nodeValue);
  end;

  repeat
    LCurrrentValueNode := LNodeList.nextNode;
    if Assigned(LCurrrentValueNode) then
      Memo2.Lines.Add(LCurrrentValueNode.nodeValue)
    else
      Break;
  until True;
end;

and XML

 

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02">
  <BkToCstmrStmt>
    <Stmt>
      <Acct>
        <Id>
          <IBAN>FI0434270410003403</IBAN>
        </Id>
      </Acct>
    </Stmt>
    <Stmt>
      <Acct>
        <Id>
          <IBAN>FI7542316072000169</IBAN>
        </Id>
      </Acct>
    </Stmt>
  </BkToCstmrStmt>
</Document>

Any idea why getElementsByTagName doews not return Tags it should (I think).

 

Once you're set to do something pretty simple and nothing works. I remember now why I do not enjoy the M$Xml too much.

 

Also if you can recommend better replacement XML libraries, feel free to do so.

 

Edited by Tommi Prami

Share this post


Link to post

I myself mostly use MSXML2_TLB.pas imported from the type library of Microsoft XML itself, not Delphi's take on it which makes things unneccessarily complicated.

Also what you may need is to set LDocument.setProperty('SelectionNamespaces','xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02"'); to make it work

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×