How to determine if a xml is well-format

A

ad

I want to determinate if a xml is well-format and valid before export it to
database.
We can determinate if xml is valid from the article:
http://support.microsoft.com/kb/307379/en-us?ln=en-us&sd=gn&fr=0

But how can we determine if a xml is well-format?
like the xml below is not well format(the end tag of ProductName)

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE Product SYSTEM "Product.dtd">
<Product ProductID="123">
<ProductName>Rugby jersey</ProductNameaa>
</Product>
 
R

Richard Blewett [DevelopMentor]

Validation will only succeed if the document is well-formed so you don't need to do anything extra beyond what is described in that article. Remeber however, that the XmlValidatingReader is based on the streaming API and so it won't know whether the document is valid until it has read the whole document: e.g.

XmlValidatingReader r = ...

while( r.Read() )
{
}

will consume the whole document and validate it.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I want to determinate if a xml is well-format and valid before export it to
database.
We can determinate if xml is valid from the article:
http://support.microsoft.com/kb/307379/en-us?ln=en-us&sd=gn&fr=0

But how can we determine if a xml is well-format?
like the xml below is not well format(the end tag of ProductName)

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE Product SYSTEM "Product.dtd">
<Product ProductID="123">
<ProductName>Rugby jersey</ProductNameaa>
</Product>
 

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

Top