/ / Come posso ottenere tutti gli attributi HTML con GeckoFX / C # - c #, javascript, gecko, geckofx

Come posso ottenere tutti gli attributi HTML con GeckoFX / C # - c #, javascript, gecko, geckofx

In C # viaGeckoFx, non ho trovato un metodo per trovare tutti gli attributi di un elemento.

Per fare ciò, ho creato una funzione JavaScript. Ecco il mio codice

GeckoWebBrowser GeckoBrowser = ....;
GeckoNode NodeElement = ....; // HTML element where to find all HTML attributes

string JSresult = "";
string JStext = @"
function getElementAttributes(element)
{
var AttributesAssocArray = {};
for (var index = 0; index < element.attributes.length; ++index) { AttributesAssocArray[element.attributes[index].name] = element.attributes[index].value; };
return JSON.stringify(AttributesAssocArray);
}

getElementAttributes(this);
";

using (AutoJSContext JScontext = new AutoJSContext(GeckoBrowser.Window.JSContext)) { JScontext.EvaluateScript(JStext, (nsISupports)NodeElement.DomObject, out JSresult); }

Avete altri suggerimenti per ottenere questo in C # (senza Javascript)?

risposte:

1 per risposta № 1

La proprietà GeckoElement.Attributes consente l'accesso a attributi di elementi.

Ad esempio, questo è un codice non testato e non compilato:

public string GetElementAttributes(GeckoElement element)
{
var result = new StringBuilder();
foreach(var a in element.Attributes)
{
result.Append(String.Format(" {0} = "{1}" ", a.NodeName, a.NodeValue));
}

return result.ToString();
}