Project

Profile

Help

DocumentFragment and DocumentWrapper

Added by Anonymous almost 20 years ago

Legacy ID: #2952409 Legacy Poster: kendall shaw (queshaw)

Hi, I create a DocumentFragment, expecting to have it have 2 child elements which are the document element from 2 different documents, using: Node n = doc1.importNode(doc2.getDocumentElement(), true); DocumentFragment df = doc1.createDocumentFragment(); df.appendChild(doc1.getDocumentElement()); df.appendChild(n); DOMSource ds = new DOMSource(df); ... trans = tf.newTransformer(xsltStreamSource); trans.transform(ds, sr); And I get an error: java.lang.IllegalArgumentException: DocumentWrapper#wrap: supplied node does not belong to the wrapped DOM document. Am I expecting the wrong thing from importNode?


Replies (6)

Please register to reply

RE: DocumentFragment and DocumentWrapper - Added by Anonymous almost 20 years ago

Legacy ID: #2961547 Legacy Poster: Michael Kay (mhkay)

Sorry, but Saxon doesn't support a DOMSource that contains a DocumentFragment rather than a Document node as its root. Michael Kay

RE: DocumentFragment and DocumentWrapper - Added by Anonymous almost 20 years ago

Legacy ID: #2976385 Legacy Poster: kendall shaw (queshaw)

Well, this barely qualifies as a Saxon question, but I'll try. I want to merge n XML documents and be able to use the id() function in saxon 6.5.3, and I don't think I can move to JAXP 1.3. I've created a SAX XMLFilter that merges XML documents one of which, in my test, uses an XML schema. While Xerces does validate the document, it doesn't create SAX attributes for IDs as type ID, it creates them as type CDATA.... So, what is a good way to merge n documents while preserving IDs (assuming there will never be a conflict between IDs), or otherwise allowing XSLT to use id()?

RE: DocumentFragment and DocumentWrapper - Added by Anonymous almost 20 years ago

Legacy ID: #2976416 Legacy Poster: kendall shaw (queshaw)

I should add that the id attributes are declared as IDs. Xerces complains if there are duplicate IDs, for example. Also, I should point out that I want to use id() not key().

RE: DocumentFragment and DocumentWrapper - Added by Anonymous almost 20 years ago

Legacy ID: #2976418 Legacy Poster: Michael Kay (mhkay)

If you're feeding SAX events into Saxon to provide the transformation input, then presumably you have control over the attribute type supplied in the Attributes object. If you set it to "ID", then Saxon will recognize the value as an ID for the purposes of the id() function. On the other hand, it might be a lot simpler to use the key() function instead of the id() function. Michael Kay

RE: DocumentFragment and DocumentWrapper - Added by Anonymous almost 20 years ago

Legacy ID: #2976451 Legacy Poster: kendall shaw (queshaw)

Okay. But I can't tell if the attribute was type ID in the schema from inside the ContentHandler because the parser is telling me it is of type CDATA, unless I use prior knowledge of the document to match attribute names, which I don't want to do. Arghh...

RE: DocumentFragment and DocumentWrapper - Added by Anonymous almost 20 years ago

Legacy ID: #2976621 Legacy Poster: kendall shaw (queshaw)

Okay, if anyone cares. Xerces 2.6.2 supports PSVIProvider, so I can cast it's XMLReader (not SAXParser as it's docs say) into a PSVIProvider and then get type information inside startElement() in the ContentHandler part of my XMLFilter.

    (1-6/6)

    Please register to reply