I want to use an regex in javascript to match all xml nodes in a text file which has some other text in it as well.
I tried using <NotificationMessage>(.|\n)+[STATUS_CHANGE]*<\/NotificationMessage>
for matching the NotificationMessage
nodes in it but the regex is not limited to the element, it captures additional text as well.
I have also tried with /<NotificationMessage>(.|\r\n)+?<\/NotificationMessage>/g
but this ignores the 'Name' node of notification described in the text below.
By this I mean that i want to selectively pick some XML nodes in a large text files which is containing huge padding data of logs and this is nowhere related to XML Parsing as mentioned by some folks
example text:
.. bla b;la bla some text of large log.......<?xml version="1.0" encoding="UTF-8"?><NotificationMessage>
<Header>
<Name>STATUS_CHANGE</Name>
<Description/>
<SomeOher/>
</Header>
<Body>
<Values>
<Key="Good" timeStamp="2017-11-01T17:47:11.7107581Z" type="xsd:string"><![CDATA[12343656]]></Key>
</Values>
</Body>
<Faults/>
</NotificationMessage>
#SOME other text continued..
.. bla b;la bla some text.......
<?xml version="1.0" encoding="UTF-8"?><NotificationMessage>
<Header>
<Name>SOME_OTHER NOTIFICATION</Name>
<Description/>
<SomeOher/>
</Header>
<Body>
<Values>
<Key="Good" timeStamp="2017-11-01T17:47:11.7107581Z" type="xsd:string"><![CDATA[12343656]]></Key>
</Values>
</Body>
<Faults/>
</NotificationMessage>
#SOME other text with $pec1Al ch@r@cters continued..
Edit 1
I have already tried an alternative solution :
var log = `Long stream of text containing above text with XML`
var regexp = /<NotificationMessage>(.|\r\n)+?<\/NotificationMessage>/g;
var matches_array = log.match(regexp);
for (let i = 0; i < matches_array.length; i++) {
if(matches_array[i].indexOf("STATUS_CHANGE")>0){
console.log(matches_array[i]);
}
But I want to do all this in 1 regular expression so as to improve performance. Also suggest would it really make a performance improvement or not.
Edit 2
Also my use case for this does not involve parsing of the extracted XMLs instead I have to dump it,so I want to avoid use of XML parsers