Hello,
I am using the sax parser to parse a XML file. It works fine, but I don't want to parse the content of an <info>
tag as it contains HTML which I want to save to a string. Can anyone tell me is there any way to go about doing this?.
Thanks
Hello,
I am using the sax parser to parse a XML file. It works fine, but I don't want to parse the content of an <info>
tag as it contains HTML which I want to save to a string. Can anyone tell me is there any way to go about doing this?.
Thanks
This is pseudocode. Adapt before use. Use at your own risk.
This will not take care of <info> tags nested inside the outer info tag.
init:
ignore = false;
startElement:
if (!ignore) {
if (element.name == "info") {
ignore = true;
} else {
process normally
}
}
endElement:
if (ignore) {
if (element.name == "info") {
ignore = false;
}
} else {
process normally
}
Though question. The best might be to preprocess the stream, escaping the part between <info>
and </info>
yourself. You could for example write a wrapper around the input stream that transforms your input on the fly, such that what the SAX parser gets is valid XML only.
Is your XML very large? If not - you can load it all into a string then use XPath queries to access nodes of interest