V
V
Vimake2014-01-02 14:49:08
C++ / C#
Vimake, 2014-01-02 14:49:08

c# data parsing

How to parse from text

<akk>name4</akk>
<ud>43</ud>
<sa>crag</sa>

How to parse in c#

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
AlexP11223, 2014-01-02
@AlexP11223

Well, if this is such a simple example, then you can use anything like string.IndexOf + string.Substring or RegExp.
And so apparently XML / HTML parsers.
Built-in XMLReader or LINQ To XML, HtmlAgilityPack.

Z
zobo, 2014-01-02
@zobo

using System;
using System.Xml.Linq;

namespace TestConsoleApplication
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var xml = "<?xml version='1.0' encoding='UTF-8' ?><root><akk>name4</akk><ud>43</ud><sa>crag</sa></root>";

            var doc = XDocument.Parse(xml);

            var rootElmnt = doc.Element("root");

            var akkElmnt = rootElmnt.Element("akk");
            var akk = akkElmnt != null ? akkElmnt.Value : null;

            var udElmnt = rootElmnt.Element("ud");
            var ud = udElmnt != null ? udElmnt.Value : null;

            var saElmnt = rootElmnt.Element("sa");
            var sa = saElmnt != null ? saElmnt.Value : null;

            Console.Write(string.Format("akk={0}, ud={1}, sa={2}", akk, ud, sa));
            Console.ReadKey();
        }
    }
}

K
Kerman, 2014-01-04
@Kerman

If it's HTML, then that's how it should be written.
There is such a component in WinForms - WebBrowser.
You can drive HTML into the browser's Documents property and parse it using the built-in methods of the component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question