c# - How to check name of element with WriteEndElement -


i'm writing xml xmlwriter. code has lots of sections this:

xml.writestartelement("payload"); thirdpartylibrary.serialise(results, xml); xml.writeendelement(); // </payload> 

the problem thirdpartylibrary.serialise method unreliable. can happen (depending on variable results) doesn't close tags opens. consequence, writeendelement line perverted, consumed closing library's hanging tags, rather writing </payload>.

thus i'd make checked call writeendelement checks element name, , throws exception unless cursor @ expected element.

xml.writeendelement("payload"); 

you can think of xmlreader.readstartelement(name) throws unless cursor @ expected place in document.

how can achieve this?


edit: second use case extension method make own code more readable , reliable.

xmlwriter writes given xml information in stream out validation. if validation while writing xml tags, performance problem arise while creating big xml file.

creating xml file using xmlwriter developer risk. if want such kind of validation, can use xmldocument.

if want validation in xmlwriter, have create writer using string or stringbuilder. because, if use stream or textwriter can't read information written stream in middle of writing. in every update of xml have read string , write own method validate written information.

i suggest use xmldocument creating these type of xml.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -