Mr doubt
Mr doubt

Reputation: 65

XML view issue in ASP.NET web page

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.

Upvotes: 0

Views: 70

Answers (1)

user2316116
user2316116

Reputation: 6824

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.

Upvotes: 2

Related Questions