Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   XML (https://www.delphipraxis.net/46-xml/)
-   -   Delphi XML Attribut auslesen - Konnte nicht in Typ (OleStr) konvertiert werden (https://www.delphipraxis.net/176890-xml-attribut-auslesen-konnte-nicht-typ-olestr-konvertiert-werden.html)

Back2Code 2. Okt 2013 14:04

XML Attribut auslesen - Konnte nicht in Typ (OleStr) konvertiert werden
 
Also ich bin grad dran Attribute auszulesen aus einer Xml. Das klappt soweit auch ganz gut bis zum jetzigen Moment. Ich bekomme die Meldung beim Versuch das Attribut status auszulesen.

Bis sLangId klappt alles wunderbar und danach kommt der Fehler. Hab durchs googlen / Dokumentation lesen leider so gut wie nichts rausbekommen und bevor ich noch mehr Zeit in Recherchen stecke die eventuell an der falschen Stelle angesetzt sind frage ich hier mal nach.

https://dl.dropboxusercontent.com/u/...5945000183.png

Delphi-Quellcode:
type
  XMLDocument: TXMLDocument;

var
  i, j: Integer;
  sPath:            String;                                                     // Pfad zur Sprachxml
  sTaskType:        String;                                                     // Import oder Transfer
  sContext:         String;
  sOriginalStatus:  String;
  sNativeText:      String;
  sLangId:          String;
  sStatus:          String;
  sTranslated:      String;
  TransNodes:       IXMLNodeList;

begin
    if OpenDialog.Execute then
    begin
      try
        sPath := OpenDialog.FileName;
        edFilePath.Text := (sPath);
        XMLDocument.LoadFromFile(sPath);
        if Assigned(XMLDocument) then
        begin
          TransNodes := XMLDocument.DocumentElement.ChildNodes['targets'].ChildNodes['target'].ChildNodes['stringdata'].ChildNodes;

          for i := 0 to 100 {TransNodes.Count} -1 do
          begin
            sContext       := TransNodes[i].Attributes['name'];
            sOriginalStatus := TransNodes[i].Attributes['status'];

            //ShowMessage(IntToStr(TransNodes[i].ChildNodes.Count));      // 6 childs beim debug

            for j := 0 to TransNodes[i].ChildNodes.Count -1 do
              begin
                if TransNodes[i].ChildNodes[j].NodeName = 'native' then
                  sNativeText    := TransNodes[i].ChildNodes['native'].Text;
                 // Delete(sNativeText, Length(sNativeText), 1);
                 // Delete(sNativeText, 1, 1);

                if TransNodes[i].ChildNodes[j].NodeName = 'lang' then
                  sLangId := TransNodes[i].ChildNodes[j].Attributes['id'];
                  //sStatus := TransNodes[i].ChildNodes[j].Attributes['status'];
                  //sTranslated := TransNodes[i].ChildNodes[j].Text;

              Memo.Lines.Add(sContext + ' ' + sOriginalStatus + ' ' + sNativeText + ' ' + sLangId + ' ' + sStatus + ' ' + sTranslated);
              end;

          end;

        end;
      finally

      end;
    end;
end;

taveuni 2. Okt 2013 14:55

AW: XML Attribut auslesen - Konnte nicht in Typ (OleStr) konvertiert werden
 
Dann hast Du bei dem Element nichts (NULL) drin.
Vorher auf .NULL oder .ISNULL oder so abfragen.

Back2Code 2. Okt 2013 15:52

AW: XML Attribut auslesen - Konnte nicht in Typ (OleStr) konvertiert werden
 
Zitat:

Zitat von taveuni (Beitrag 1230651)
Dann hast Du bei dem Element nichts (NULL) drin.
Vorher auf .NULL oder .ISNULL oder so abfragen.

Wie kann ich das genau auf .Null abfragen? Bei Nil meckert er rum ...

taveuni 2. Okt 2013 15:59

AW: XML Attribut auslesen - Konnte nicht in Typ (OleStr) konvertiert werden
 
Zitat:

Zitat von Back2Code (Beitrag 1230659)
Bei Nil meckert er rum ...

Und bei NULL?

Back2Code 2. Okt 2013 16:01

AW: XML Attribut auslesen - Konnte nicht in Typ (OleStr) konvertiert werden
 
Zitat:

Zitat von taveuni (Beitrag 1230661)
Zitat:

Zitat von Back2Code (Beitrag 1230659)
Bei Nil meckert er rum ...

Und bei NULL?

So gehts mit Nil aber jetzt bekomm ich dummerweise nen Listenindex überschreitet Fehler -.-

Delphi-Quellcode:
                  try
                    if TransNodes[i].ChildNodes[j].Attributes['status'] <> NULL then
                    sStatus := TransNodes[i].ChildNodes[2].Attributes['status'];
                  except
                  //
                  end;

taveuni 2. Okt 2013 16:04

AW: XML Attribut auslesen - Konnte nicht in Typ (OleStr) konvertiert werden
 
Dann bist Du auf einem Inexistenten Listenindex.
Debugger?

Mikkey 2. Okt 2013 16:24

AW: XML Attribut auslesen - Konnte nicht in Typ (OleStr) konvertiert werden
 
Zitat:

Zitat von Back2Code (Beitrag 1230662)
So gehts mit Nil aber jetzt bekomm ich dummerweise nen Listenindex überschreitet Fehler -.-

Versuch's mal mit
Delphi-Quellcode:
                    if TransNodes[i].ChildNodes[j].Attributes['status'] <> NULL then
                    sStatus := TransNodes[i].ChildNodes[j].Attributes['status'];
Statt "[2]"


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:22 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz