🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.xml
2 messages
2 total messages Started by Stefan M. Huber Mon, 23 Jun 2008 10:00
Too stupid for XPath?
#210
Author: Stefan M. Huber
Date: Mon, 23 Jun 2008 10:00
41 lines
2016 bytes
Hi!

   I am trying to use XPath in a D2005 application. But I fail, of course.
The problem is that nodeValue of the selected nodes is always empty.

The test XML string that I read and assign to an xml document is this:
<?xml version="1.0" encoding="iso-8859-15"?>
<root>
<title>title test</title>
<p>paragraph 1</p>
<p>paragraph 2</p>
</root>

Here's the test code that I use:

function getContent(APath: widestring): TXMLTextList; stdcall;
var root : IDOMNodeSelect;
     nl   : IDOMNodeList;
     i    : integer;
     node : IDOMNode;
begin
_doc := NewXMLDocument;
_doc.Active := true;
_doc.LoadFromXML('<?xml version="1.0"  
encoding="iso-8859-15"?><root><title>title test</title><p>paragraph  
1</p><p>paragraph 2</p></root>');
root := _doc.DocumentElement.DOMNode as IDOMNodeSelect;
nl := root.selectNodes(APath);
if nl <> nil then
   begin
   for i := 0 to nl.length - 1 do
     begin
     ShowMessage(nl.Item[i].nodeName + ': ' + nl.item[i].nodeValue);
     end;
   end;
end;

Using 'p' as APath parameter, I get two showmessage calls with only 'p: '  
as text. Where's the nodeValue?

Stefan
Re: Too stupid for XPath?
#211
Author: Stefan M. Huber
Date: Mon, 23 Jun 2008 11:40
17 lines
1416 bytes
On Mon, 23 Jun 2008 12:00:34 +0200, Stefan M. Huber <looseleaf@gmx.net>
wrote:

> Hi!
>
>    I am trying to use XPath in a D2005 application. But I fail, of  
> course.
> The problem is that nodeValue of the selected nodes is always empty.

OK, found it. There's obviously no nodeValue but a collection of
childNodes. And if there's a TEXT_NODE this is what I thought to be the
nodeValue. Thus I iterate through the child nodes.

If anyone sees my just cancelled posting: I changed the XML in the wrong  
place...

Stefan
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads