Home c# XML Paraceing Tools C #

XML Paraceing Tools C #

Author

Date

Category

There is an XML file view:

& lt; time & gt;
  & lt; Name & GT; Birch & Lt; / Name & GT;
  & lt; Age & gt; 3 & lt; / age & gt;
  & lt; node & gt;
    & lt; Name & gt; List1 & lt; / Name & gt;
    & lt; Age & gt; 1 & lt; / age & gt;
  & lt; / node & gt;
  & lt; node & gt;
    & lt; Name & gt; List2 & lt; / Name & gt;
    & lt; Age & gt; 1 & lt; / age & gt;
  & lt; / node & gt;
  & lt; Tree & GT;
   & lt; Name & gt; Peach & Lt; / Name & GT;
   & lt; Age & gt; 3 & lt; / age & gt;
   & lt; node & gt;
     & lt; name & gt; sheet11 & lt; / name & gt;
     & lt; Age & gt; 1 & lt; / age & gt;
   & lt; / node & gt;
   & lt; node & gt;
     & lt; Name & gt; List22 & lt; / Name & gt;
     & lt; Age & gt; 1 & lt; / age & gt;
   & lt; / node & gt;
  & lt; / tree & gt;
& lt; / tree & gt;

How to go through the document and fill in the form structures:

struct tree
{
  INT NAME;
  Int Age.
}
Struct Node.
{
 INT NAME;
 INT AGE;
}
Tree T;
Node N;
If (& lt; Tree & GT;)
 T.NAME = NAME;
 T.age = AGE;
ELSE.
  N.Name = Name;
  N.age = AGE;

Answer 1, Authority 100%

In this way, http://ideone.com/y8kog .

using system;
Using System.Collections.Genic;
Using System.xml;
Using System.xml.Serialization;
Using System.io;
Using System.Linq;
Public Class Node.
{
  Public String Name;
  Public String Age;
}
Public Class Tree.
{
  Public String Name;
  Public int age;
  [Xmlelement ("Node")]
  Public List & LT; Node & GT; nodes;
  [Xmlelement ("Tree")]
  Public List & LT; Tree & GT; Trees;
}
Public Class Test
{
  Public Static Void Main ()
  {
    var xml = @ "& lt; xml version =" "1.0" "encoding =" "UTF-8" "? & gt; ...";
    VAR Reader = New StringReader (XML);
    VAR Result = (Tree) New Xmlserializer (Typeof (Tree). Deserialize (Reader);
  }
}

Answer 2

Use Linq to XML. Very comfortable thing.
Here is an article on this topic http://habrahabr.ru/post/24673/

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions