Josema Alonso wrote:

Hi, all.

When I run a query against one of my collections I get something like this:
<?xml version="1.0"?>
<EquipmentType id="mic" xmlns:src="http://xml.apache.org/xindice/Query";
src:col="/db/xmtrader/Recording/Equipment/EquipmentType" src:key="mic">
 <Description lang="en">Microphone</Description>
 <Description lang="es">Microno</Description>
</EquipmentType>

<?xml version="1.0"?>
<EquipmentType id="player" xmlns:src="http://xml.apache.org/xindice/Query";
src:col="/db/xmtrader/Recording/Equipment/EquipmentType" src:key="player">
 <Description lang="en">Player</Description>
 <Description lang="es">Reproductor</Description>
</EquipmentType>

<?xml version="1.0"?>
<EquipmentType id="preamp" xmlns:src="http://xml.apache.org/xindice/Query";
src:col="/db/xmtrader/Recording/Equipment/EquipmentType" src:key="preamp">
 <Description lang="en">Preamplifier</Description>
 <Description lang="es">Preamplificador</Description>
</EquipmentType>

More or less is what I expected, but I'd prefer to have a root element named
'EquipmentTypes' and I would need to get rid of the xml declaration in every
element. Is it possible?


If you're treating this as a DOM Document, you can iterate over

over the Nodes in it, grabbing only the ProcessingInstructions:

   Document doc = getDocument();
   NodeIterator ni = DocumentTraversal.createNodeIterator(doc,
       NodeFilter.SHOW_PROCESSING_INSTRUCTION,true);
   Node n = doc;
   ProcessingInstruction pi = null;
   while ( n != null ) {
       pi = (ProcessingInstruction)ni.nextNode();
       if ( pi.getTarget().equals("xml") ) doc.removeNode(pi);
   }

[I just wrote this off the top of my head, so it might not work directly]

Since these are simply Nodes, you can remove them from the Document
upon encountering them in the Iterator.

As for having a single root, I don't quite understand the context
under which you could receive multiple roots as separate Elements,
so I'll leave the answer to that to others. If they are truly from
separate Documents, you can always create a new Document and use
importNode(Node,true).


Murray

......................................................................
Murray Altheim                  <http://kmi.open.ac.uk/people/murray/>
Knowledge Media Institute
The Open University, Milton Keynes, Bucks, MK7 6AA, UK

           If you're the first person in a new territory,
           you're likely to get shot at.
                                                    -- ma



Reply via email to