ASP.NET MVC: colouring specific parts on an XML

Viewed 253

I am trying to display the content of an XML on a page. I need to color two sections of that XML in a specific color but I have some troubles doing it. I'm using the following code:

<pre class="xmlPreviewTextArea">@XDocument.Parse(Model).ToString()</pre>

The content of the XML looks like that:

<myRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <header>
    <code xsi:type="xsd:string">78161083705</code>
  </header>
  <ch>
    <new_ch>
      <ch_code xsi:type="xsd:string">8116478</ch_code>
      <span style="color: orange;">
        <ch_add_line_2 xsi:type="xsd:string">ryytyyrt</ch_add_line_2>
        <ch_add_postcode xsi:type="xsd:string">15263</ch_add_postcode>
      </span>
    </new_ch>
  </ch>
  <card>
    <crd_iss>
      <ch_code xsi:type="xsd:string">6789177</ch_code>
      <span style="color: orange;">
        <fulfil_data_6 xsi:type="xsd:string">PROJECT</fulfil_data_6>
      </span>
    </crd_iss>
  </card>
</myRequest>

The problem is that the two span tags are not interpreted and I'm not sure how to do it properly.

Thanks for your help!

1 Answers

I think you can use css stylesheet for format your xml file

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/css" href="xml.css"?>
<myRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <header>
    <code xsi:type="xsd:string">78161083705</code>
  </header>
  <ch>
    <new_ch>
      <ch_code xsi:type="xsd:string">8116478</ch_code>
      <span style="color: orange;">
        <ch_add_line_2 xsi:type="xsd:string">ryytyyrt</ch_add_line_2>
        <ch_add_postcode xsi:type="xsd:string">15263</ch_add_postcode>
      </span>
    </new_ch>
  </ch>
  <card>
    <crd_iss>
      <ch_code xsi:type="xsd:string">6789177</ch_code>      
        <fulfil_data_6 xsi:type="xsd:string">PROJECT</fulfil_data_6>      
    </crd_iss>
  </card>
</myRequest>

and examle xml.css

myRequest { 
display:block;  
              border: 1px solid silver; 
              margin:0.5em;  
              padding:0.5em;  
              background-color:whitesmoke;  
} 

 fulfil_data_6 { 
     color : orange; 
} 
Related