Search code examples
c#xmldocument

c# how to get XML tag values from a simple XML schema


I have a XML that I get from other application that its structure is like this:

<uid>1DE23B0B-1601-4E48-B8F5-7D3152A815A1</uid>
<status>1</status>

Is there a way how can I get the values without using XMLDocument, actually I even don't know if XMLDocument can load a XML with these simple schema.

Any clue?


Solution

  • You can parse your pseudo-xml via regex like this:

    internal class Data
    {
        public string UId { get; set; }
        public string Status { get; set; }
    
        public Data(string text)
        {
            string strRegex = @"<uid>(.*?)</uid>.*?<status>(.*?)</status>";
            Regex myRegex = new Regex(strRegex, RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
    
            var match = myRegex.Match(text);
            UId = match.Groups[1].Value;
            Status = match.Groups[2].Value;
        }
    }