Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I'm requesting xml from the website to get the ip address location.

but i'm getting this error..

<quote>
Expected DTD markup was not found. Line 1, position 3.


my code:
C#
protected void Location(string ip)
        {
            String url = String.Empty;

            if (ip.Trim() != String.Empty)
            {
                url = String.Format("http://iplocationtools.com/ip_query2.php?ip={0}", ip.Trim());
               // XDocument xDoc = XDocument.Load(url);
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(url); //Error
                if (xDoc == null)
                {
                    throw new ApplicationException("Data is not Valid");
                }

                Xml1.TransformSource = "IP.xslt";
                Xml1.DocumentContent = xDoc.ToString();
            }
        }


plzzz suggest me, thanks
Posted

HTML is not XML[^] you better use one of .net html parser [^]

check Html Agility Pack[^] for example.
C#
url = String.Format("http://iplocationtools.com/ip_query2.php?ip={0}", ip.Trim());
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);
 
Share this answer
 
The content returned in the HTTP response through url is not valid XML, due to some issues with the metadata part of it called DOCTYPE. You can download the content in question without parsing it and review, to see what's wrong with it. Note that DOCTYPE can be prescribed with one or more XML external entities which could be downloaded separately and might be not available to your parser, by some reason.

To understand what's wrong, you should lean the XML standard in general and DOCTYPE declarations (especially just the syntax). Please see:
http://en.wikipedia.org/wiki/Document_type_definition[^],
http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-doctypedecl[^],
http://www.w3schools.com/dtd/dtd_entities.asp[^],
http://www.w3schools.com/DTD/dtd_intro.asp[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900