0


I need to validate string

string parameter="<HostName>Arasanalu</HostName><AdminUserName>Administrator</AdminUserName><AdminPassword>A1234</AdminPassword><PlaceNumber>38</PlaceNumber>"

While converting to correct xml I will be adding Root element:

if (string.IsNullOrEmpty(value) == false)
{
    // Try to load the value into a document
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml("<root>" + value + "</root>");
    return true;
}

I want to Validate my string which will be converted to XML format with XML Schema. please let me know which is the best procedure ?

backtrack
  • 7,996
  • 5
  • 52
  • 99
channa
  • 215
  • 1
  • 3
  • 10

1 Answers1

0

Well according to me you can try and load the xml using "LoadXml" method of XmlDocument object (just as you have mentioned in your question) and put it in try..catch block. If the xml is not in correct format it will throw an exception.

You can check the following link

Others might have a better solution though.

Regards,

Samar

Community
  • 1
  • 1
samar
  • 5,021
  • 9
  • 47
  • 71