On Aug 18, 9:29 pm, Havvy <[email protected]> wrote:
> I intend to get the node with flash object by parsing the dom tree.
> When I use the dom.GetElementsByTagName() to put all the node of the
> dom into a node list, I can find a node with nodeName="OBJECT".
> <code>
> // get the node list with tag = "object"
> nsCOMPtr<nsIDOMNodeList> objNodeList;
> PRUint32 length = 0;
> res = domDocument->GetElementsByTagName(NS_LITERAL_STRING("*"),
> getter_AddRefs(objNodeList));
> if (NS_FAILED(res))
> return NS_ERROR_FAILURE;
> else if (objNodeList){
> objNodeList->GetLength(&length);
> printf("================>node list length:%d\n", length);
> }
> for (PRUint32 index = 0; index < length; index++) {
> nsCOMPtr<nsIDOMNode> childNode;
> objNodeList->Item(index, getter_AddRefs(childNode));
> if (!childNode)
> continue;
> nsAutoString nodeName;
> childNode->GetNodeName(nodeName);
> if
> (strcasecmp(NS_LossyConvertUTF16toASCII(nodeName).get(), "OBJECT") ==
> 0)
> printf("%d node name is %s\n", index,
> NS_LossyConvertUTF16toASCII(nodeName).get());
> }
> </code>
>
> But when i want to get the flash node by the tag name "OBJECT", the
> length of nodeList is 0.
> <code>
> res = domDocument->GetElementsByTagName(NS_LITERAL_STRING("OBJECT"),
> getter_AddRefs(objNodeList));
> </code>
>
> Why can't get the node with nodeName="OBJECT" directly?
> Please give me some advices. Thanks in advance.
>
> -- Havvy
One may want to know where the "domDocument" comes from. "mWebBrowser"
is the webbrowser init the URI LOAD.
Since I could get all the nodes with "*", the domDocument entity
should be the right one, right?
<code>
// get the nsIDomWindow from nsIWebBrowser
nsCOMPtr<nsIDOMWindow> domWindow;
nsresult res = mWebBrowser->GetContentDOMWindow(getter_AddRefs
(domWindow));
if (NS_FAILED(res))
return NS_ERROR_FAILURE;
if (!domWindow) {
return NS_ERROR_FAILURE;
}
// get the nsIDomDocument from nsIDomWindow
nsCOMPtr<nsIDOMDocument> domDocument;
res = domWindow->GetDocument(getter_AddRefs(domDocument)); //
Get document
if (NS_FAILED(res))
return NS_ERROR_FAILURE;
if (!domDocument) {
return NS_ERROR_FAILURE;
}
</code>
Thanks!
-- Havvy
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding