![]() |
SelectSingleNode gibt nil, obwohl ich ein Node erwarte...
Huhu DPler :hi:
ich bin seit langem mal wieder hier und habe auch gleich ein Problemchen :) Es geht um eine SVG, die ich aus einem Adobe-Mars-Archiv extrahiert habe (Adobe Mars ist eine Technologie, die PDF-Dokumente mit allem Drum und Dran in XML abbildet). Jedenfalls lade ich die SVG mithilfe des MSXML6-Parsers und möchte nun auf einen bestimmten Knoten zugreifen. Jedoch bekomme ich alsResultat immer nil :( Die SVG:
XML-Code:
Mein Delphi-Code:
<?xml version="1.0" encoding="utf-8"?>
<svg xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:pdf="http://ns.adobe.com/pdf/2006" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" stroke="none" width="595" height="841"> <defs> <color-profile name="cs-0" xlink:href="/color/cs-0.icc" pdf:Count="3" pdf:type="RGB" pdf:wp="0.9505 1 1.089" pdf:bp="0 0 0" pdf:r="0.4124 0.2126 0.0193" pdf:g="0.3576 0.7152 0.1192" pdf:b="0.1805 0.0722 0.9505"/> <pdf:Separation Name="cs-1" Colorant="HKS 66" AlternateSpace="cs-0"> <pdf:TintTransform> <pdf:SampledFunction Domain="0 1" Range="0 1 0 1 0 1" Size="255" BitsPerSample="8" Order="linear" Encode="0 254" Decode="0 1 0 1 0 1"> <pdf:File Name="/res/func-0.f0"/> </pdf:SampledFunction> </pdf:TintTransform> </pdf:Separation> <font-face font-family="F0"> <font-face-src> <font-face-name name="AGaramond-Regular"/> <font-face-uri xlink:href="/font/f-0._sfnt"/> </font-face-src> </font-face> <font-face font-family="F1"> <font-face-src> <font-face-name name="AGaramond-Semibold"/> <font-face-uri xlink:href="/font/f-1._sfnt"/> </font-face-src> </font-face> <clipPath id="cl-1"> <path d="M0,841h595V0H0z"/> </clipPath> <clipPath id="cl-2"> <path d="M0.015,840.99h594.99V0H0.015z"/> </clipPath> </defs> <g transform="matrix(1 0 0 -1 0 841)"> <g clip-path="url(#cl-1)"> <g clip-path="url(#cl-2)"> <path stroke="rgb(0,0,0) device-color(DeviceGray,0)" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" d="M56.12,797H538"/> <text transform="matrix(1 0 0 -1 0 801.5599)" font-size="9.5" font-family="F0" fill="rgb(0,0,0) device-color(DeviceGray,0)" fill-rule="evenodd"> <tspan x="56.14 60.889 100.0794 104.7239 110.993 116.5401 121.7925 127.045 132.5921 140.0297 145.7582 152.8443 157.4888 162.1333 168.7444 176.4004 182.527 188.0741 191.2841 196.9413 204.0274 211.465 218.5605 224.1075 231.5451 489.5204 494.165 500.586 506.2233 508.5688 511.1841 515.9332 519.0387 523.7878 528.5369 533.2859">64STELLENAUSSCHREIBUNGEN SVBl 2/2001</tspan> </text> </g> </g> </g> </svg>
Delphi-Quellcode:
Ich möchte schlicht und einfach das erste <text>-Element bekommen, das im Dokument vorkommt....
var
xmldoc: IXMLDOMDocument3; tempnode: IXMLDOMNode; //..... xmldoc := CoDOMDocument60.Create(); xmldoc.setProperty('NewParser', true); xmldoc.async := false; xmldoc.load(extractfilepath(paramstr(0))+'working\pg.svg'); if xmldoc.parseError.errorCode = 0 then begin tempnode := xmldoc.documentelement.selectSingleNode('//text'); end; Habt ihr eine Idee, was ich falsch mache? Danke schonmal, aeno :) |
Re: SelectSingleNode gibt nil, obwohl ich ein Node erwarte..
Schau doch mal nach (parseErrors.ErrorCode o.ä.), ob das Dokument überhaupt korrekt geladen wurde. Ansonsten stelle mal sicher, dass die Datei auch im UTF-8 Format gespeichert wurde.
...:cat:... |
Re: SelectSingleNode gibt nil, obwohl ich ein Node erwarte..
Zitat:
Das ist kurios :( aeno |
Re: SelectSingleNode gibt nil, obwohl ich ein Node erwarte..
Zitat:
Es wird eine Exception mit hilfreicher Meldung ausgelöst, was in diesem Falle ja auch völlig korrekt ist, da man ja nicht weiterparsen darf.
Delphi-Quellcode:
procedure CheckDocumentError(const document:IXMLDOMDocument);
var msg : string; err : IXMLDOMParseError; begin err := document.parseError; if err.errorCode <> 0 then begin msg := err.reason + #13#10 + Format('Zeile: %d, Position: %d, Text: "%s"',[err.line,err.linepos,err.srcText]); if err.url <> '' then msg:=msg+#13#10+'URL: '+err.url; //raise EXmlError.Create(msg); // wer mag, kann eine eigene Exception-Klasse definieren raise Exception.Create(msg); end; end; |
Re: SelectSingleNode gibt nil, obwohl ich ein Node erwarte..
Hallo Steffen,
du hast NewParser konfiguriert, aber dein Dokument ist nicht kompatibel. Versuche es so:
Delphi-Quellcode:
Grüße vom marabu
var
xmldoc: IXMLDOMDocument; tempnode: IXMLDOMNode; fn: TFileName; begin fn := ExtractFilePath(ParamStr(0)) + 'working\pg.svg'; xmldoc := CoDOMDocument.Create(); xmldoc.async := False; if xmldoc.load(fn) then begin tempnode := xmldoc.selectSingleNode('//text'); if Assigned(tempNode) then ShowMessage(tempnode.xml) else ShowMessage('try again later'); end else CheckDocumentError(xmldoc); end; |
Re: SelectSingleNode gibt nil, obwohl ich ein Node erwarte..
Danke marabu! :D
Das Problem war zwar nicht NewParser (in meinem Code auf False setzen brachte keine Verbesserung). Es lag jedoch viel mehr an der Deklaration von xmlDoc und dessen Erstellung! Ich habe IXMLDOMDocument3 und CoDOMDocument60.Create() verwendet. Marabus Variante ohne die Ziffern funktioniert. Vielen Dank nochmal euch allen :) aeno |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:16 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