Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show Xml data in the winform in the XML fashion?

My winform application communicates with the web service. For some requirement, I need to present the web service response in the XML format in the winform application.

I can serialize the response type (class) instance to XML string. But when i show that string in the rich text box, it's obviously displayed as continuous string; not as the XML as shown below.

<UserServiceAccesses>
- <UserServiceAccess>
-   <Service>
       <ID>0</ID> 
       <LocalID>Loggerr</LocalID> 
       <SystemID>-1</SystemID> 
       <ServiceType>U</ServiceType> 
       <Name>MyLogger</Name> 
       </Service>
    <ClientPermissions /> 
  </UserServiceAccess>
- <UserServiceAccess>
-     <Service>
         <ID>0</ID> 
         <LocalID>Logger2</LocalID> 
         <SystemID>-1</SystemID> 
         <ServiceType>U</ServiceType> 
         <Name>MyLogger2</Name> 
     </Service>
     <ClientPermissions /> 
  </UserServiceAccess>
<UserServiceAccesses>

Here, UserServiceAccesses is the class which has property of type UserServiceAccess. Then UserServiceAccess has a properties of type Service, ClientPermissions

How can I do it? It can be in any form (tree, table, text etc.) but it should be readable as XML. Since there are many web methods we call from application, everytime XML structure would be different and so we cannot have definite schema.

like image 864
Learner Avatar asked Jul 05 '11 12:07

Learner


People also ask

How can you load an XML file directly into a DataSet?

To fill a DataSet with data from XML, use the ReadXml method of the DataSet object. The ReadXml method reads from a file, a stream, or an XmlReader, and takes as arguments the source of the XML plus an optional XmlReadMode argument.

How do I open an XML file in Visual Studio?

On the File menu, point to New, and click File. Select XML File in the Templates pane and click Open. A new file is opened in the editor.

How do I add an XML file to Visual Studio?

Add the XML file to Visual Studio ProjectOpen up Visual Studio and create a new project or open an existing one. Add an existing item to the C# project. – Select the XML file we created earlier and press Add. – The file will be added to the project.


1 Answers

Try to apply indent to the xmlText, like:

XDocument xDocument = XDocument.Parse(xmlText);
myRichTextBox.Text = xDocument.ToString();//ToString will format xml string with indent
//as XDocument class overrides ToString and return xml with indent
like image 138
Jalal Said Avatar answered Oct 20 '22 23:10

Jalal Said