Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    22

    HtmlElement.GetAttribute("class") non funziona

    Ciao a tutti,
    Ho usato il seguente codice per scrivere su file di testo l attributo class
    e i l tag corrispondente,
    ma non so perche l attributo class non lo vede. Ho provato con align e va
    il codice:


    private void webBrowser1_DocumentCompleted(object sender,
    WebBrowserDocumentCompletedEventArgs e)
    {
    HtmlDocument doc=webBrowser1.Document;
    HtmlElementCollection Elem = doc.GetElementsByTagName("TD");
    System.Text.StringBuilder str = new System.Text.StringBuilder();

    string str2 = PrintDom(Elem, new StringBuilder(), 0);
    FileInfo f = new FileInfo("visura.txt");
    StreamWriter w = f.CreateText();
    w.WriteLine(str2);
    w.Close();
    MessageBox.Show("scrittura completata");

    }


    private string PrintDom(HtmlElementCollection elemColl,
    System.Text.StringBuilder returnStr,Int32 depth)
    {
    System.Text.StringBuilder str = new System.Text.StringBuilder();

    foreach (HtmlElement elem in elemColl)
    {
    string elemName;

    elemName = elem.GetAttribute("class");
    if (elemName == null || elemName.Length == 0)
    {
    elemName = "no Class";
    }

    str.Append(' ', depth * 4);
    str.Append(elemName + ": "+elem.TagName + "(Level " + depth
    + ")");
    returnStr.AppendLine(str.ToString());

    if (elem.CanHaveChildren)
    {
    PrintDom(elem.Children, returnStr, depth + 1);
    }

    str.Remove(0, str.Length);
    }

    return(returnStr.ToString());
    }

    come posso fare?
    Grazie in anticipo

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2006
    Messaggi
    559
    prova con la property CssClass
    se nella vita avro avuto la possiblita di aiutare qualcuno non avro vissuto invano (E. Dikinson)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.