0

XML view issue in ASP.NET web page. Users are inserting XML data from Ajax, HTML editor, but when I am viewing that data into Label Its not showing page is not going down also. Below is my XML Data inserted into the SQL table.

<!--[if gte mso 9]><xml> <w:WordDocument>  <w:View>Normal</w:View>  <w:Zoom>0</w:Zoom>  <w:TrackMoves/>  <w:TrackFormatting/>                  <w:PunctuationKerning/>  <w:ValidateAgainstSchemas/>  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>  <w:DoNotPromoteQF/>  <w:LidThemeOther>EN-US</w:LidThemeOther>  <w:LidThemeAsian>X-NONE</w:LidThemeAsian>  <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>  <w:Compatibility>   <w:BreakWrappedTables/>   <w:SnapToGridInCell/>   <w:WrapTextWithPunct/>   <w:UseAsianBreakRules/>   <w:DontGrowAutofit/>   <w:SplitPgBreakAndParaMark/>   <w:DontVertAlignCellWithSp/>   <w:DontBreakConstrainedForcedTables/>   <w:DontVertAlignInTxbx/>   <w:Word11KerningPairs/>   <w:CachedColBalance/>   <w:UseFELayout/>  </w:Compatibility>  <m:mathPr>   <m:mathFont m:val="Cambria Math"/>   <m:brkBin m:val="before"/>   <m:brkBinSub m:val="--"/>   <m:smallFrac m:val="off"/>   <m:dispDef/>   <m:lMargin m:val="0"/>   <m:rMargin m:val="0"/>   <m:defJc m:val="centerGroup"/>   <m:wrapIndent m:val="1440"/>   <m:intLim m:val="subSup"/>   <m:naryLim m:val="undOvr"/>  </m:mathPr></w:WordDocument></xml><![endif]--> <p class="MsoListParagraph"><span style='font-size: 12pt; line-height: 115%; font-family: "times new roman","serif";'>In most of the naxal hitrural remote locations Govt. Schools are the single available source ofeducation, but the quality of education at these schools is a serious concern. About48% of children in grade V cannot solve the division problems; about half ofthe children in grade V cannot read out contents of grade II. In general thenumerical abilities, language, analytical skills and conceptual development areat present severely missing in the learning system. T</span><span style='font-family: "times new roman","serif";'>  from the local  adf proper methods and techniques of teachingand learning in dfa block.</span></p><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"  DefSemiHidden="true" DefQFormat="false" DefPriority="99"  LatentStyleCount="267">  <w:LsdException Locked="false" Priority="0" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Normal"/>  <w:LsdException Locked="false" Priority="9" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>  <w:LsdException Locked="false" Priority="9" QFormat="tru

I am showing the data into a label like below.

 lit__Input.Text = ds.Tables[0].Rows[0]["lit_Input"].ToString();

How can I see an XML Data into Label or Other Controls.

1 Answer 1

2

The Label control in ASP.NET will be rendered as <span> tag with the value of the Text property. Your value seems to have html comment <!-- in front of it and therefore nothing will be shown when Label is rendered. You can check it if your right click on the page - View Source.

Use Server.HtmlEncode() to encode xml

lit__Input.Text = Server.HtmlEncode(ds.Tables[0].Rows[0]["lit_Input"].ToString());

Note, that the example above has invalid XML - it starts with <!--[if gte mso 9]><xml> and ends by QFormat="tru which is not valid XML. See how it looks like on the plain HTML page https://jsbin.com/geyexuzebe/edit?html,output - it breaks the entire page and you will not see "end of test" at the end of the page.

Sign up to request clarification or add additional context in comments.

4 Comments

But its showing as it is data. I do not need xml to display and only display text data inside of xml. @smirnov
What is your complete XML? If you see your example above - it starts with <!--[if gte mso 9]><xml> and ends by QFormat="tru which is not valid XML
Actually I given some validation to ajax html editor so its storing like that ends tag. Is there any other solution. @smirnov
Again, your XML is not valid and might not be displayed properly because of its format. If you use ´lit__Input.Text = Server.HtmlEncode()´ - it works (shows plain XML but works). If you do not use ´Server.HtmlEncode()´ content is not shown and also the entire page looks broken, right? If true, it means it is due to XML content and therefore you have to check and correct it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.