Generate LINQ to XML C # code from an XML document?

Does anyone know a tool that will generate LINQ to XML code from a real XML document or fragment? This is reverse engineering a common XML generation script.

For example, I want to provide an XML fragment as input, such as

<root> <thing>value</thing> </root> 

and generate the equivalent C # LINQ to XML code snippet in this way

 var x = new XElement("root", new XElement("thing", new XText("value")); ); 

Although I'm looking for a quick one, I'm sure some enterprising people will tell me to quit my own and provide some awesome reference code.

+4
source share
2 answers

See this tool .

The application supports:

  • XDocument
  • XDeclaration
  • XProcessingInstruction
  • XComment
  • XNamespace
  • XElement
  • XAttribute

  • creation of business objects

  • Linq To Xml code generation (with variables, in the method, extracting the code corresponding to the selected nodes)

  • you can open the xml file or directly copy to xml file in richtextbox

  • The editor allows you to create Xml documents from scratch or add / modify existing Xml documents.
  • the editor has several types that are synchronized (text, tree)
  • help with capture (tags and attributes of automatic completion and verification during the formation of xml) for a text view, ...
  • you can also publish data of nodes selected in datagridview
  • etc.
+6
source

This is not difficult to do using T4 templates or XSL transforms, but I don’t know who did it.

0
source

Source: https://habr.com/ru/post/1347022/


All Articles