Saturday, 15 January 2011

html - VB.NET / C#.Net MSHTML: Unable to get "name" attribute from Outerhtml after using "setAttribute('name',value)" for certain elements -



html - VB.NET / C#.Net MSHTML: Unable to get "name" attribute from Outerhtml after using "setAttribute('name',value)" for certain elements -

i developing wysiwyg application company usage custom integration company's existing tools.

i unable "name" attribute out of elements when trying html string using ".outerhtml", input tag element.

code example: `dim inelem windows.forms.htmlelement = hdoc.createelement("input")` `inelem.id = "txt01"` `inelem.setattribute("name", inelem.id)` `inelem.setattribute("type", "text")` `inelem.setattribute("placeholder","text here....")` '' append created element html body `hdoc.body.appendchild(inelem)` --> getting html string: ** hdoc.body.getelementbyid("txt01").outerhtml => "<input id=txt01 placeholder='text here....'></input>" --> want is: ** hdoc.body.getelementbyid("txt01").outerhtml => "<input id=txt01 placeholder='text here....' type='text' name='txt01'></input>"

yes, not name attribute missing, other too. (e.g. type) help me on matter?

solution attempted: each inputele windows.forms.htmlelement in hdoc.body.getelementsbytagname("input") ctype(inputele.domelement, mshtml.ihtmlinputelement).name = inputele.id next

** failed ** :(

ultimate solution: utilize html agility pack: ---------------------- dim inputele3 htmlagilitypack.htmlnode = new_wb.createelement("input") inputele3.attributes.add("id", "txt01") inputele3.attributes.add("name", inputele3.id) inputele3.attributes.add("type", "text") inputele3.attributes.add("placeholder", "text here ....") result: ------- inputele3.outerhtml => <input id="txt01" name="txt01" type="text" placeholder="text here ...." >

it works now, provided utilize htmlagilitypack.dll :( microsoft mshtml sucks! :(

this worked me. forgive me using dynamic datatype, not have mshtml library on visual studio reason.

private void form1_load(object sender, eventargs e) { this.webbrowser1.navigate("about:blank"); this.webbrowser1.document.write("<input id='hell' class='blah' placeholder='text here' name='hell' type='text'></input>"); dynamic htmldoc = webbrowser1.document.domdocument dynamic; dynamic node = htmldoc.getelementbyid("hell") dynamic; string x = node.outerhtml; //gets name not type string s = node.getattribute["type"]; //gets type string name = node.getattribute["name"]; //gets name }

so outerhtml per did not attribute, when calling getattribute method did work. hopefuly helps.

c# html vb.net mshtml outerhtml

No comments:

Post a Comment