Reputation: 31998
I have googled, searched and read, but have been unable to find an answer.
I have XML-files that look somewhat like this:
<Patient PID="5" Disease="Flu" FavoriteBird="Norwegian Blue"/>
<Patient PID="33" Disease="Thripshaw's Disease" FavoriteBird="Dodo">
<Contact Hospitalized="2013 05 30"/>
</Patient>
I want to anonymise each patients' favorite bird. That is, produce output that looks like this:
<Patient PID="5" Disease="Flu"/>
<Patient PID="33" Disease="Thripshaw's Disease">
<Contact Hospitalized="2013 05 30"/>
</Patient>
It is all going swimmingly, except for the fact that I can only handle the last type of patient tag- that is, when the element is not self-closing.
My "endElement"-method simply looks like
out.write(qName + "/n>")
and is never invoked for the first type of Patient tag.
What do I do? If there was a way to find out whether a tag is self-closing or not I could easily fix it.
PS: I have to transform files that are up to several hundred megabytes in size. Please keep that in mind when suggesting alternative solutions.
Upvotes: 1
Views: 1291
Reputation: 311023
You can do this in about five lines of XSLT, rather than the undoubtedly many more lines of SAX handling you have now, and it will work correctly for any legal XML.
Upvotes: 1