Hi Josema,
  I don't know if you're still struggling with the query results to strip
away the xml declaration and the added attributes, but this may help you:

  public Document combineXPathResults(String resultRootElement,
                                      ResourceSet result)
    throws XMLDBException
  {
    // Create a new Document and a root element that will have as children
    // all the results
    Document resultDoc = new DocumentImpl();
    Element root = resultDoc.createElement(resultRootElement);
    resultDoc.appendChild(root);

    // Iterate the xpath results and add each of them to the main Document
    ResourceIterator iterator = result.getIterator();
    while(iterator.hasMoreResources()) {
      Resource r = iterator.nextResource();

      Element resElement = ((Document)
        ((XMLResource)r).getContentAsDOM()).getDocumentElement();

      // Remove unwanted attributes
      resElement.removeAttribute("src:col");
      resElement.removeAttribute("src:key");
      resElement.removeAttribute("xmlns:src");

      // Add this result to the root element
      Element importedElement = (Element)resultDoc.importNode(resElement,
true);
      root.appendChild(importedElement);
    }

    return resultDoc;
  }

Once you have the "global" result Document object you can serialize it
(using the XMSerialize class), or apply an xslt to it (using Xalan), or
anything you need to.

Cheers,
  Andrea


> -----Original Message-----
> From: Josema Alonso [mailto:[EMAIL PROTECTED]
> Sent: Thursday, 14 November 2002 3:02 AM
> To: [email protected]
> Subject: Re: how to get rid of the xml declaration on results?
>
>
> Hey,
>
> Remember the weird characters? The function below, which is really stupid,
> makes the parse work, just by rewriting the characters from the XML string
> with the same ones. So, I'm now sure it is an encoding issue, and I do not
> know how to fix other way. Any ideas on how to retrieve the
> resources in the
> right encoding?
>
> Thanks.
>
> -------------
> /**
>  * Removes those nasty characters from the resource
>  *
>  */
> private String removeNasty(String data) throws
> UnsupportedEncodingException
> {
>  char oldChar = new String("\n").charAt(0);
>  char newChar = new String("\n").charAt(0);
>  data = data.replace(oldChar, newChar);
>
>  newChar = new String("\t").charAt(0);
>  oldChar = new String("\t").charAt(0);
>  data = data.replace(oldChar, newChar);
>
>  return data;
> }

Reply via email to