Hi,

I'm writing an XPCOM component that, as a part of it's job, is supposed 
to load an XML document and traverse the DOM. The component is supposed 
to be used in a XULRunner application. I'm using the 
document.implementation.createDocument to create an object implementing 
the nsIDOMXMLDocument interface, and then call it's load method. The 
problem is that I can not get documentElement in C++. I have a feeling 
I'm doing something completely wrong here. :)

1. I tried passing the XUL document's nsIDOMDocument from JavaScript to 
the component and then doing the following:

// error checking stripped
nsCOMPtr<nsIDOMDOMImplementation> docImpl;
xulDocument->GetImplementation ( getter_AddRefs(docImpl) );

nsCOMPtr<nsIDOMDocument> domDoc;
docImpl->CreateDocument ( NS_LITERAL_STRING(""), 
NS_LITERAL_STRING("xmlDoc"), nsnull, getter_AddRefs(domDoc) );

nsCOMPtr<nsIDOMXMLDocument> domXmlDoc ( do_QueryInterface ( domDoc ) );

PRBool boolRes;
domXmlDoc->Load ( url, &boolRes );

nsCOMPtr<nsIDOMElement> documentElement;
domDoc->GetDocumentElement ( getter_AddRefs(documentElement) );

In this case, xmlDoc->Load returns NS_OK and boolRes has PR_TRUE, but 
when I'm calling domDoc->GetDocumentElement, it returns null. However, 
if I return domDoc to the calling JavaScript, I can access the 
documentElement and traverse the DOM.

2. I tried loading the document in JavaScript and then passing the 
loaded document's nsIDOMDocument to the component, but still 
GetDocumentElement returns null. Even if I get the loaded document's 
documentElement and pass it's nsIDOMElement to the component, the 
component receives null even though it was non-null on JavaScript side.

What am I missing here?

Thank you,
-- Vitaly

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to