Hey, just a quick followup.
Since this is giving so much problems, what if:
1.- I get the content as text and not as DOM
2.- I apply the suggested functions so I can clean it up
3.- I load it into a DOM document with something like:
private Document load(String s) {
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(new StringBufferInputStream(s));
}
I guess this is not a too clean approach, but it seems this time Xindice is
taking me there...any better ideas?
I need some sleep now...
----- Original Message -----
From: "Josema Alonso" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, November 12, 2002 2:54 AM
Subject: Re: how to get rid of the xml declaration on results?
> Hello,
>
> > I asked this some days ago too, but there was no real solution besides
> > hacking code of Xindice.
> I see...ughhh...
>
> > The <EquipmentTypes /> Tag, u have to set by yourself, cause u are
> getting
> > a resultset.
> Ok, I already did it.
>
> > the declaration can be killed by
> > ----------------------------------------------
> > data= data+xml.substring(xml.indexOf("?>")+2);
> > -----------------------------------------------
> > for the
> >
> > "xmlns:src="http://xml.apache.org/xindice/Query"
> > src:col="/db/xmtrader/Recording/Equipment/EquipmentType" src:key="mic"
> >
> > stuff i found a really bad solution, it "overreads" just that stuff and
> > gives the string back to u without it.
> > ....
> Thanks, I'll apply it, too.
>
> > hope that helps
> Sure it does. Thanks a lot.
>
> Btw, when I get the resources list I would like to add it to a document.
> This will be a document fragment, the method should return a DOM Node and
> this one will be after that added to the root element I already created.
I'm
> trying the usual iterating through the ResourceSet and creating the
fragment
> in the method, but it is giving me an eception, something like 'DOM005
Wrong
> document'. I do not know what's happening, any ideas? (code attached
below).
>
> Thanks a lot :-)
>
> ----------------
> /**
> * Search for documents in the DB. If not found, return null.
> * The rootCollection is initialized in the constructor
> * I'm trying to return the fragment in xmldoc but it gives the exception
> :-(
> */
> public Node find(String subCol, String xpath) throws Exception {
> Collection col = null;
> Node xmldoc = null;
> try {
> Class c = Class.forName(driver);
>
> Database database = (Database) c.newInstance();
> DatabaseManager.registerDatabase(database);
>
> String localCol = rootCollection + subCol;
>
> col = DatabaseManager.getCollection(localCol);
>
> XPathQueryService service =
> (XPathQueryService) col.getService("XPathQueryService", "1.0");
> ResourceSet resultSet = service.query(xpath);
> ResourceIterator results = resultSet.getIterator();
> while (results.hasMoreResources()) {
> Resource res = results.nextResource();
>
>
>
System.out.println((((XMLResource)res).getContentAsDOM().getFirstChild()));
> if(xmldoc!=null) {
> Node childNode = ((XMLResource)res).getContentAsDOM().getFirstChild();
> xmldoc.appendChild(childNode);
> }
> else {
> xmldoc = ((XMLResource)res).getContentAsDOM().getFirstChild();
> }
> }
> return (xmldoc);
> }
> catch (XMLDBException e) {
> System.err.println("XML:DB - Find Exception occured " + e.errorCode);
> throw e;
> }
> finally {
> if (col != null) {
> col.close();
> }
> }
> }
>
>
> I'd like to invoke this method from this one:
> /**
> * Inititializes a DOM Node to list the available Equipment types
> *
> */
> public void initEquipmentTypes() {
> DOMImplementation impl;
> try {
> // Find the implementation
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
> factory.setNamespaceAware(true);
> factory.setValidating ( false );
> DocumentBuilder builder = factory.newDocumentBuilder();
> impl = builder.getDOMImplementation();
> }
> catch (Exception ex) {
> throw new RuntimeException("Failed to initialize DOM factory. Root
cause:
> \n" + ex);
> }
>
> //Create the node for the root, 'Class'
> Document doc = impl.createDocument( null, "EquipmentTypes", null);
> equipmentTypes = doc.getDocumentElement();
>
> //find the Equipment Types available in the database
> String localSubCol = "/Recording/Equipment/EquipmentType";
> try {
> //Here is where I create an instance and call the method above
> //result is not null but it gives an exception
> XindiceManager xi = new XindiceManager();
> Node result = xi.find(localSubCol, "//EquipmentType");
>
> if (result!=null) {
> equipmentTypes.appendChild(result);
> }
> }
> catch (Exception e) {
> System.err.println("Cannot get results from the DB: " + e.getMessage());
> }
> }
>
>