Recent

Author Topic: [XML] TDOMNode.NodeValue is empty  (Read 796 times)

CC

  • Full Member
  • ***
  • Posts: 149
[XML] TDOMNode.NodeValue is empty
« on: March 28, 2022, 10:55:05 am »
Hi,

this is quite strange:

VER:
FPC 3.2 up to date fixes branch
document: xml version="1.0" encoding="UTF-8"

The first few levels are only categories. Here is where reading the actual data begins:

After    iNode:= CategoryNode .FirstChild is  executed
    1. iNode.NodeName has the right value;
    2. but iNode.NodeValue is always empty even though it always has a value in the file.

Debugging uncovered  that this function is called to get the value:

Code: Pascal  [Select][+][-]
  1. function TDOMNode.GetNodeValue: DOMString;
  2. begin
  3.   Result := '';
  4. end;  


Which explains why NodeValue is always empty, but I would expect some overridden function to be called instead with access to the actual value.
iNode.NodeType = ELEMENT_NODE. But after checking the DOM unit's source neither TDOMElement nor it's ancestors have any overridden GetNodeValue.  The only such overridden function is

Code: Pascal  [Select][+][-]
  1. function TDOMCharacterData.GetNodeValue: DOMString;
  2. begin
  3.   Result := FNodeValue;
  4. end;
  5.  

So it seems iNode.NodeType should be a TEXT_NODE instead of ELEMENT_NODE. Why is it not?


This should be so simple. Where am I going wrong?



   
« Last Edit: March 28, 2022, 11:55:26 am by CC »

CC

  • Full Member
  • ***
  • Posts: 149
Re: [XML] TDOMNode.NodeValue is empty
« Reply #1 on: March 28, 2022, 12:13:25 pm »
The answer to my question is so trivial:

iNode.TextContent should be used instead of iNode.NodeValue

 

TinyPortal © 2005-2018