How to capture an XML node while parsing with SAX
I'm working on a Java Web Start distributor application. It uses a configuration XML which defines how to serve resources to clients. There are some resources which are generated during the requests. I'm processing the main configuration file with a custom SAXParser handler.
In the configuration file i would l开发者_Go百科ike to add an embedded XML definition part which has the servable XML document's root node as a child node.
For example:
<Resources>
<!-- other resource definitions -->
<EmbeddedXMLResource mapsForRequest="embedded.xml">
<HiThere>
<ThisIsAnEmbeddedXMLDocument/>
</HiThere>
</EmbeddedXMLResource>
<!-- ... -->
</Resources>
I'm wondering if there's any way of reading the <HiThere>
node to a DOM document or at least capture the inner contents of <EmbeddedXMLResource>
into a String skipping the SAX processing?
I thought about putting the embedded content into a CDATA section. This way i can read the embedded XML as a text node but i'll lose syntax highlighting in editors on embedded nodes.
Perhaps...
- On startElement HiThere get the start position in file with the locator
- On endElement HiThere get the end position also.
- Open the xml resource with an other Reader, and extract the relevant part as string, and so on.
Funny.
精彩评论