views:

20

answers:

2

Hi all, I'm writing a Mozilla component to get all the links from a page an write them into a file using XPCOM and C++. I get all the links into an array like this:

//doc is a pointer to nsIDOMDocument
doc->GetElementsByTagName(NS_LITERAL_STRING("A"), getter_AddRefs(nodeList));
nodeList->GetLength(&nodeNumb);
href = new nsEmbedString[nodeNumb];

for(PRUnit32 i=0; i< nodeNumb; i++){
   nsCOMPtr<nsIDOMNode> aNode;
   nodeList->Item(i, getter_AddRefs(aNode));
   nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
   if(anchor){
      (*outLinks)++;
      href[i] = anchor->GetHref(tempHref);  
   }
 } // end of for

but now how can I get them write to a file. I'm really clue less how to work with file in XPCOM. Can some one please give me some hints or links to tutorials please?

A: 

You've probably seen nsIFile, which does offer an IsWriteable() method but no write(). You'd want nsILocalFile::openANSIFileDesc(), which returns an ordinary FILE*.

MSalters
That means you have to worry about closing the file yourself and leaves you to deal with platform specific issues.
sdwilsh
A: 

You'll want to use an nsIFileOutputStream.

sdwilsh