Bisma Jayadi schrieb: > Hi all... > > I'm currently developing a Lazarus application which need to read an XML > file. In order to do such a task, FPC has provided DOM unit (dom.pp). > But, it seems that dom.pp is unable to read XML element's (text) value. > It succesfully read element's name (through NodeName property) and > attributes (name and value) though. Getting element's name (through > NodeValue property) always return an empty string. > > What did I do wrong? Or am I missing something about the dom.pp usage? > Here are the codes I used... > > procedure TForm1.Button1Click(Sender: TObject); > var > doc: TXMLDocument; > begin > ReadXMLFile(doc, 'sample.xml'); > > // this returns correct first attribute's name > > Memo1.Lines.Add(doc.DocumentElement.FirstChild.Attributes.Item[0].NodeName);
btw, you can leave out the ".Item" part, as it's a default property. So "Attributes[0]" would be sufficient. > // this returns correct first attribute's value > > Memo1.Lines.Add(doc.DocumentElement.FirstChild.Attributes.Item[0].NodeValue); > > // this returns correct first element's name > Memo1.Lines.Add(doc.DocumentElement.FirstChild.FirstChild.NodeName); > // this returns nothing !!! > Memo1.Lines.Add(doc.DocumentElement.FirstChild.FirstChild.NodeValue); Perhaps it contains whitespace? It's possible that the XML parser creates more than one text node. Do you have an excerpt of your XML file? This would be very helpful. - Sebastian _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal