[XML-SIG] How can I search for a string of text
Andrew M. Kuchling
Wed, 21 Apr 1999 19:01:46 -0400 (EDT)
>I need to remove a string from my HTML files but I don't know the best way to
>find it. There are usually line feeds in the HTML between the string so the
>string does not appear as one DOM text node. Does anyone know the best way to
>find contiguous text that spans multiple DOM nodes?
The normalize() method on an Element node consolidates the
subtree so there are no adjacent Text nodes, merging Text nodes that
are next to each other into a single node. So you could do
document.rootElement.normalize(), and then rely on the string being
contained within one node. That won't catch tricky cases -- do you
need to find it if an entity expands to the string, or to part of the
string? if the string had a PI in the middle of it, would it still
count as a match? -- but it'll certainly help with the simple case.
A.M. Kuchling http://starship.python.net/crew/amk/
It is not that I wanted to know a great deal, in order to acquire what is now
called expertise, and which enables one to become an expert-tease to people
who don't know as much as you do about the tiny corner you have made your own.
-- Robertson Davies, _The Rebel Angels_