the output below generated third party tool validates xml files against xml schema. output validation errors. ok, little context.
from errors above displayed in html, want able perform "syntax highlighting" using perl. instance, want able highlight parts of text above.
specifically, want colour text conforms "line [0-9]*" bold , in red. i've tried experiment regex search , replace i've not been successful.
any pointers/hints fantastic.
thank you!
line 8: element 'alphabet', attribute 'letters': value 'xyz' not match fixed value constraint 'abc'. line 185: element 'drink': attribute 'coffee' required missing. line 254: element 'timeout': element not expected. line 269: element 'commands': element not expected. expected 1 of ( eat, drink, sleep ). line 812: element 'software': attribute 'version' required missing. line 876: element 'windows-software': attribute 'version' required missing. line 890: element 'contact': attribute 'telephone' required missing. line 890: element 'operating': attribute 'mode' required missing.
have try this:
#!/usr/bin/perl use strict; use warnings; while(<data>) { s#(line \d+)#<span style="font-weight:bold;color:red;">$1</span>#; s#(element\s|attribute\s)('[^']*')#$1<span style="font-weight:bold;color:blue;">$2</span>#g; print } __data__ line 8: element 'alphabet', attribute 'letters': value 'xyz' not match fixed value constraint 'abc'. line 185: element 'drink': attribute 'coffee' required missing. line 254: element 'timeout': element not expected.
output
<span style="font-weight:bold;color:red;">line 8</span>: element <span style="font-weight:bold;color:blue;">'alphabet'</span>, attribute <span style="font-weight:bold;color:blue;">'letters'</span>: value 'xyz' not match fixed value constraint 'abc'. <span style="font-weight:bold;color:red;">line 185</span>: element <span style="font-weight:bold;color:blue;">'drink'</span>: attribute <span style="font-weight:bold;color:blue;">'coffee'</span> required missing. <span style="font-weight:bold;color:red;">line 254</span>: element <span style="font-weight:bold;color:blue;">'timeout'</span>: element not expected.
instead of style attribut, can use css class.
s#(line \d+)#<span class="bold_red">$1</span>#;
Comments
Post a Comment