Содержание
Класс Xml
Класс Xml предназначен для чтения Xml документов.
Для создания объекта предназначена функция CreateXml.
Пример:
Procedure OnCreate;
Var
X, S : Xml;
Text : String;
Begin
X := CreateXml(LoadFile('c:\WordDocument.xml'));
// Заголовок документа
Text := X.Childs('o:DocumentProperties').Childs('o:Title').Text;
Alert(Text, 'Заголовок документа');
// Все стили документа
S := X.Childs('w:styles').Childs('w:style'); // Эта команда пропустит w:versionOfBuiltInStylenames и w:latentStyles
While S.Fetch Do
Text := Text + S.Childs('wx:uiName').Prop('wx:val') + Chr(10);
Alert(Text, 'Стили');
// Получаем текст
Text := GetText(X.Childs('w:body'));
Alert(Text, 'Текст в документе');
End;
Function GetText(S : Xml) : String;
Begin
S := S.Childs('');
While S.Fetch Do
Begin
If S.IfName('w:t') Then Result := Result + S.Text
Else Result := Result + GetText(S);
If S.IfName('w:p') Then Result := Result + chr(10);
End;
End;
справка