General XMetaL Discussion
spyro July 2, 2009 at 9:46 am
Not able to access textnodes per XPath expressionJuly 2, 2009 at 9:46 amParticipants 2Replies 3Last Activity 13 years, 7 months ago
In my current project I'm looping through the member elements of a nodeset trying to concatenate all descendant textnodes of them in a string using the node.getNodesByXpath-instruction. I can access attribut values without problems but I'm not able to read the content of the text itself.
I made a dead-simple testdocument like this:
To access the text “What's up?” I use the xpath-instruction “//element/text()”.
Inside a XMetaL-macro the line
returns a empty string instead of the expected “What's up?”. The property “length” gives me the value “0” instead of 1. What am I doing wrong?
Rupert Jungtonys July 5, 2009 at 11:38 pm
Reply to: Not able to access textnodes per XPath expressionJuly 5, 2009 at 11:38 pm
My guess is that you're seeing text nodes containing white space that you're not expecting. For example, the newline between
and will probably appear as a text node.dcramer July 6, 2009 at 2:03 am
Reply to: Not able to access textnodes per XPath expressionJuly 6, 2009 at 2:03 am
(added // before “element” in the xpath)spyro July 6, 2009 at 7:00 am
Reply to: Not able to access textnodes per XPath expressionJuly 6, 2009 at 7:00 am
you're right, of course. I forgot this to add this to my post here in the first case (I've corrected that know). My problem is, that exactly this expression “//element/text()” doesn't give me the expected result.
Furthermore I am not able to correctly address the content within element 1 with the expression “//element//text()” which should deliver 2 textnodes (“Hello ” and “world!”) instead of an empty element.
- You must be logged in to reply to this topic.