Check if valid XML doc

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

Hi
I have a text box where I can paste XML docs into and then send them
however sometimes the call fails I assume to incorrectly formatted text! it
fails on the line below:

doc.LoadXml(txtToSend.Text.ToString)

How can I check if the text constitutes a valid XML xml document before
loading it?

Thanks
 
Adrian said:
Hi
I have a text box where I can paste XML docs into and then send them
however sometimes the call fails I assume to incorrectly formatted text! it
fails on the line below:

doc.LoadXml(txtToSend.Text.ToString)

How can I check if the text constitutes a valid XML xml document before
loading it?

Thanks

I think you are checking. Look at the exception that is being thrown,
it probably tells you that your xml is poorly formatted. Catch the
exception and handle it accordingly.

Chris
 
Adrian said:
I have a text box where I can paste XML docs into and then send them
however sometimes the call fails I assume to incorrectly formatted text!
it fails on the line below:

doc.LoadXml(txtToSend.Text.ToString)

How can I check if the text constitutes a valid XML xml document before
loading it?

You could attempt to load the document and catch the exception which is
thrown when loading fails.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top