Can you send me the the program please

Bill Phillips wrote:

> I need to parse a URL into a nsIDOMHTMLDocument.  Using the code below I was
> able to successfully do that, but when I step through the nodes of the
> document and try to do a GetValue() on the text nodes I always get a blank
> line.
>
> Below is the code I'm using.  If someone can see something obviously wrong
> with it please let me know.  I have a standalone program that I can send
> anyone who wants to try it.
>
> Thanks for any help,
>
> Bill Phillips
>
>   nsString outString;
>
>   nsCOMPtr<nsIURI> url;
>   rv = NS_NewURI(getter_AddRefs(url), inString.ToNewCString());
>
>   nsCOMPtr<nsIInputStream> inputStream;
>   rv = NS_OpenURI(getter_AddRefs(inputStream), url);
>
>   NS_WITH_SERVICE(nsIWebShell, webshell, kWebShellCID, &rv);
>
>   NS_WITH_SERVICE(nsIParser, parser, kCParserCID, &rv);
>
>   nsCOMPtr<nsIDocument> doc;
>   rv = NS_NewHTMLDocument(getter_AddRefs(doc));
>
>   if (NS_FAILED(rv))
>   {
>     printf("Unable to create a parser : 0x%x\n", rv);
>     return NS_ERROR_FAILURE;
>   }
>
>   nsCOMPtr<nsIHTMLContentSink> sink;
>   rv = NS_NewHTMLContentSink(getter_AddRefs(sink), doc, url, webshell);
>   parser->SetContentSink(sink);
>
>   parser->SetContentSink(sink);
>   nsCOMPtr<nsIDTD> dtd = nsnull;
>   if (inType.EqualsWithConversion("text/xif"))
>     rv = NS_NewXIFDTD(getter_AddRefs(dtd));
>   else
>     rv = NS_NewNavHTMLDTD(getter_AddRefs(dtd));
>   if (NS_FAILED(rv))
>   {
>     printf("Couldn't create new HTML DTD: 0x%x\n", rv);
>     return rv;
>   }
>
>   parser->RegisterDTD(dtd);
>
>   rv = parser->Parse(*inputStream, NS_ConvertASCIItoUCS2("text/html"));
>   if (NS_FAILED(rv))
>   {
>     printf("Parse() failed! 0x%x\n", rv);
>     return rv;
>   }
>
>   nsCOMPtr<nsIDOMHTMLDocument> domdoc;
>   rv = doc->QueryInterface(nsIDOMHTMLDocument::GetIID(),
> getter_AddRefs(domdoc));
>   printf("Parse_URL() - after nsIDOMHTMLDocument QI result = 0x%x\n", rv);
>
>   nsString title;
>   domdoc->GetTitle(title);
>   printf("Parse_URL() - Document title = %s\n", title.ToNewUTF8String());
>
>   nsCOMPtr<nsIDOMHTMLElement> body;
>   rv = domdoc->GetBody(getter_AddRefs(body));
>   printf("Parse_URL() - after GetBody rv = 0x%x\n", rv);
>
>   nsCOMPtr<nsIDOMNodeList> nodelist;
>   rv = body->GetChildNodes(getter_AddRefs(nodelist));
>   printf("Parse_URL() - after GetChildNodes rv = 0x%x\n", rv);
>
>   PRUint32 numnodes;
>   nodelist->GetLength(&numnodes);
>   printf("Parse_URL() - Number of nodes = %d\n", numnodes);
>
>   nsCOMPtr<nsIDOMNode> node;
>   PRUint16 nodetype;
>   for(unsigned int i = 0; i < numnodes; i++)
>   {
>   nodelist->Item(i, getter_AddRefs(node));
>
>   node->GetNodeType(&nodetype);
>   printf("Parse_URL() - Node #%d, type is %d\n", i, nodetype);
>
>   if(nodetype == nsIDOMNode::TEXT_NODE)
>   {
>    nsAutoString nodename;
>    node->GetNodeName(nodename);
>    printf("    Parse_URL() - Node #%d, name is %s\n", i,
> nodename.ToNewCString());
>
>    nsAutoString nodevalue;
>    node->GetNodeValue(nodevalue);
>    printf("    Parse_URL() - Node #%d, value is %s\n", i,
> nodevalue.ToNewCString());
>   }
>   }


Reply via email to