How to tell if a string is xml?

后端 未结 7 1698
北荒
北荒 2021-01-11 10:44

We have a string field which can contain XML or plain text. The XML contains no header, and no root element, i.e. is not well formed.

We need t

7条回答
  •  [愿得一人]
    2021-01-11 11:18

    try
    {
        XmlDocument myDoc = new XmlDocument();
        myDoc.LoadXml(myString);
    }
    catch(XmlException ex)
    {
        //take care of the exception
    }
    

提交回复
热议问题