c# - why is XLinq reformatting my XML? -
i using xlinq (xml linq) parse xml document , 1 part of document deals representing rich-text , uses xml:space="preserve" attribute preserve whitespace within rich-text element.
the issue i'm experiencing when have element inside rich-text contains sub-element no text, xlinq reformats xml , puts element on own line. this, of course, causes additional white space created changes original content.
example:
<rich-text xml:space="preserve"> <text-run><br/></text-run> </rich-text> results in:
<rich-text xml:space="preserve"> <text-run> <br/> </text-run> </rich-text> if add space or other text before <br/> in original xml so
<rich-text xml:space="preserve"> <text-run> <br/></text-run> </rich-text> the parser doesn't reformat xml
<rich-text xml:space="preserve"> <text-run> <br/></text-run> </rich-text> how can prevent xml parser reformatting element?
is reformatting normal xml parsing or unwanted side effect of xlinq parser?
edit: parsing document this:
using (var reader = system.xml.xmlreader.create(stream)) return xelement.load(reader); i not using custom xmlreadersettings or loadoptions
the problem occurs when use .value property on text-run xelement text value of element. instead of receiving \n correct output original xml, receive
\n \n
note additional whitespace , line break due reformatting! reformatting can observed when inspecting element in debugger or calling .tostring().
have tried this:
yourxelement.tostring(saveoptions.disableformatting) this should solve problem.
btw - should similar thing on load:
xelement.parse(sr, loadoptions.preservewhitespace);
Comments
Post a Comment