08.02.2020, 22:17
|
Модератор
|
|
Регистрация: 17.04.2008
Сообщения: 8,029
Версия Delphi: 7, XE3, 10.2
Репутация: 49089
|
|
ну, вообще-то, это нарушение спецификации xml. Т.е. это правильно, что TXMLDoc падает на парсинге такого xml. Можно попробовать парсить не через XMLDoc, а через HTMLDoc (это не компонент, надо создать соотв. объект "руками"). Вот пример из одного моего проекта:
Код:
procedure TMonitorItem.SetValuesFromInternetPage(APage : String; AFirst : Boolean = True);
var
HTMLDoc: OleVariant;
HTMLElement: OleVariant;
I, J : Integer;
Buf, Buf2 : String;
AName : String;
APrice : Currency;
begin
AName := 'Item';
APrice := 0.0;
HTMLDoc := coHTMLDocument.Create as IHTMLDocument2;
HTMLDoc.Write(APage);
HTMLDoc.Close;
For I := 0 To HTMLDoc.all.length - 1 Do
Begin
HTMLElement := HTMLDoc.all.item(I);
If HTMLElement.tagName = 'META' Then
Begin
If (IDispatch(HTMLElement) as IHTMLElement5).hasAttribute('name') Then
If HTMLElement.getAttribute('name',0) = 'keywords' Then
If (IDispatch(HTMLElement) as IHTMLElement5).hasAttribute('content') Then
AName := DecodeHtmlText(HTMLElement.getAttribute('content',0));
End;
If HTMLElement.tagName = 'SPAN' Then
Begin
If (IDispatch(HTMLElement) as IHTMLElement5).hasAttribute('class') Then
If Not VarIsNull(HTMLElement.getAttribute('className',0)) Then
If HTMLElement.getAttribute('className',0) = 'itc-you-pay-price bold' Then
Begin
buf := HTMLElement.innerHTML;
If FormatSettings.DecimalSeparator = ','
Then buf := StringReplace(buf,'.',',',[])
Else buf := StringReplace(buf,',','.',[]);
Buf2 := '';
For J := 1 To Length(Buf) Do
If CharInSet(Buf[J],['0'..'9',FormatSettings.DecimalSeparator]) Then
Buf2 := Buf2 + Buf[J];
APrice := StrToCurr(buf2);
End;
End;
End;
If (AName = '') And (APrice = 0.0) Then
Raise Exception.Create('Error reading product page.');
FLastPrice := APrice;
FLastDate := Now;
If AFirst Then
Begin
FItemName := AName;
FInitPrice := APrice;
FInitDate := Now;
End;
end;
|