1

Which is the best way to convert xml to html, currently i am using Xpathnavigator and xpathnodeiterator to query and traverse the xml. This works fine, but i need to convert this xml to html,and display it in browser with some tables, which is the best way to achieve this. And the xml is not constant always, i mean the xml is generated dynamically. Xml is below:

- 
<win32_networkadapter>
<entity>
  <index>1</index> 
  <speed /> 
  <manufacturer /> 
  <pnpdeviceid /> 
  <name>RAS Async Adapter</name> 
  <adaptertype /> 
  </entity>
- <entity>
  <index>2</index> 
  <speed /> 
  <manufacturer>Microsoft</manufacturer> 
  <pnpdeviceid>ROOT\MS_L2TPMINIPORT\0000</pnpdeviceid> 
  <name>WAN Miniport (L2TP)</name> 
  <adaptertype /> 
  </entity>
</win32_networkadapter>

This xml contains the details of the network adapters in a system, to get details wmi is used and xml is generated dynamically. So one system may contain 2 network adapter as in the above xml and other system may contain 3 or 4 network adapters in which case the xml grows. In this case how can generate html from this xml dynamically. Display the network details in tables in browser.

THank you

3 Answers 3

4

XML file can be transformed to HTML using XSLT.

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

Comments

3

Instead of converting xml to html you can style the xml document itself, you can read more about that documentation, w3 for xml stylesheets, Styling XML Documents with CSS and adding style to xml

1 Comment

Using XML directly with CSS is an approach that is often neglected, so you are right to remind us of it, but it's worth pointing out that it has its limitations. Although CSS has become very powerful, I would think that organising the data in a table of rows and columns would stretch this approach to its limits.
1

There are several XSLT processors that can be invoked from C#. The Microsoft one only supports XSLT 1.0 (but that may be adequate for your needs, depending on the complexity of the transformation). There are two processors that support XSLT 2.0 for this environment: Saxon and XQSharp. Although there is a learning curve associated with XSLT, the code will be much more maintainable than any thing you write using DOM-level C# coding.

Comments

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.