How to determine if a xml is well-format

  • Thread starter Thread starter ad
  • Start date Start date
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>
 
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>
 
Back
Top