![]() |
|
#1
|
|||
|
|||
![]() Помогите разобраться с парсингом
вот нашол пример Код:
XMLDocument1.LoadFromFile('http://newyorg.myminicity.com/xml'); XMLDocument1.Active := true; Edit1.Text := XMLDocument1.DocumentElement.ChildNodes['population'].Text; Edit2.Text := VarToStr(XMLDocument1.DocumentElement.ChildNodes['bases'].Attributes['ind']); Edit3.Text := VarToStr(XMLDocument1.DocumentElement.ChildNodes['bases'].Attributes['tra']); Edit4.Text := VarToStr(XMLDocument1.DocumentElement.ChildNodes['bases'].Attributes['sec']); Edit5.Text := VarToStr(XMLDocument1.DocumentElement.ChildNodes['bases'].Attributes['env']); XMLDocument1.Active := false; а мне надо свой xml распарсить пытаюсь это зделать так Код:
procedure TForm1.Button1Click(Sender: TObject); begin XMLDocument1.LoadFromFile('1.xml'); XMLDocument1.Active := true; Memo1.Text:=XMLDocument1.XML.Text; XMLDocument1.Active := false; end; но сразу выскакивает ошибка "В текстовом комментарии обнаружен недопустимый знак" подскажите пожалуйста как сделать правильно |
#2
|
||||
|
||||
![]() У меня очки дальновидения запотели, плохо вижу открываемый файл.
Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. |
#3
|
|||
|
|||
![]() извеняюсь вот фаил
Последний раз редактировалось Gudzik11, 06.11.2011 в 00:08. |
#4
|
||||
|
||||
![]() Пока, я вижу HTML файл переименованный в XML.
Вот простой пример: Код:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <WasabiXML version="1.2"> <skininfo> <version>1.0</version> <name>Winamp5 Base Skin</name> <comment>Please feel free to use this skin as a reference point to build your new Winamp5 skins.</comment> <author gaybag="bartibartman">Sven Kistner</author> <email>sven@metrix.de</email> <homepage>http://www.winamp.com</homepage> <screenshot>screenshot.png</screenshot> </skininfo> <include file="xml/color-presets.xml"/> <include file="xml/system-colors.xml"/> <include file="standardframe/standardframe.xml" /> <include file="titlebar/titlebar.xml" /> <include file="xml/player.xml"/> <include file="xml/pledit.xml"/> <include file="xml/ml.xml"/> <include file="xml/vis.xml"/> <include file="xml/video.xml"/> <include file="xml/notifier.xml"/> <include file="about/about.xml"/> </WasabiXML> Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. Последний раз редактировалось angvelem, 06.11.2011 в 00:21. |
#5
|
|||
|
|||
![]() Скачивал я так
Код:
GetDir(0,s); memo2.Text:=Utf8ToAnsi(IdHTTP1.Get('http://xml.weather.co.ua/1.2/forecast/19?dayf=5&userid=yoursite_com')); Memo2.Text:=Memo1.Text + Memo2.Text + Memo3.Text ; Memo2.Text:=Replace(Memo2.Text,'<?xml version="1.0" encoding="UTF-8"?>',''); Memo2.Lines.SaveToFile(s+'\1.xml'); |
#6
|
||||
|
||||
![]() Ну и получил ерунду. Зачем Replace использовал?
Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. |
#7
|
|||
|
|||
![]() я в memo1 добовлял
Код:
<head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <title>Прогноз погоды</title> </head> <body> а этот кусочек остался <?xml version="1.0" encoding="UTF-8"?> вот я и решил что он не кчиму Последний раз редактировалось lmikle, 06.11.2011 в 02:04. |
#8
|
|||
|
|||
![]() а xml может быть только в utf-8
как тогда русские буквы нормально отображать? Подскажи как быть? |
#9
|
||||
|
||||
![]() Порылся в XML-файлах, попался такой:
Код:
<?xml version="1.0" encoding="windows-1251"?> <ybarmail> <box name = "name@yandex.ru" count = "17" /> </ybarmail> Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. Последний раз редактировалось angvelem, 06.11.2011 в 01:00. |
#10
|
|||
|
|||
![]() вот это уже xml ?
PHP код:
raised exception class econvertError with message 'invalid utf-8 sequence at position 178' |
#11
|
||||
|
||||
![]() Вот так открывает:
Код:
<?xml version="1.0" encoding="windows-1251"?> <forecast version="1.2" last_updated="Sat, 05 Nov 2011 22:50:17 +0200"> <url>https://weather.co.ua/show/?19</url> ... Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. |
#12
|
|||
|
|||
![]() СПАСИБО ЗАРАБОТАЛО!
А не подскажешь как считать PHP код:
если к примеру из <url>https://weather.co.ua/show/?19</url> получить эт я понял Label8.CAPTION := XMLDocument1.DocumentElement.ChildNodes['url'].Text; а вот из <t>+3</t> не знаю как |
#13
|
||||
|
||||
![]() Никогда не занимался XML-ками.
![]() Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. |
#14
|
|||
|
|||
![]() Примерно так-же, только надо идти на уровень вниз.
что-то типа (не проверял, так что только сама идея): Код:
Label8.CAPTION := XMLDocument1.DocumentElement.ChildNodes['current'].ChildElement['t'].Text; |
#15
|
|||
|
|||
![]() спасибо всё работает
|