未找到预期的DTD标记。第1行,第3位。 [英] Expected DTD markup was not found. Line 1, position 3.

查看:80
本文介绍了未找到预期的DTD标记。第1行,第3位。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我要求网站上的xml获取IP地址。



但我收到此错误..



< quote>

未找到预期的DTD标记。第1行,第3位。





我的代码:

 < span class =code-keyword> protected   void 位置( 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); // 错误
如果 (xDoc == null
{
throw new ApplicationException( 数据无效);
}

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





plzzz建议我,谢谢

解决方案

HTML不是XML [ ^ ]你最好使用 .net html解析器 [ ^ ]



查看 Html Agility Pack [ ^ ]例如。

 url =  String  .Format(  http://iplocationtools.com/ip_query2.php?ip= {0},ip.Trim()); 
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);


HTTP响应中通过 url 是无效的XML,因为它的元数据部分称为DOCTYPE存在一些问题。您可以下载有问题的内容而无需解析并查看,看看它有什么问题。请注意,可以使用一个或多个XML 外部实体来规定DOCTYPE,这些实体可以单独下载,并且由于某种原因可能无法供您的解析器使用。



要理解什么是错的,你应该通常使用XML标准和DOCTYPE声明(特别是语法)。请参阅:

http://en.wikipedia.org/wiki/Document_type_definition [< a href =http://en.wikipedia.org/wiki/Document_type_definitiontarget =_ blanktitle =New Window> ^ ],

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

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:

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

解决方案

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

check Html Agility Pack[^] for example.

url = String.Format("http://iplocationtools.com/ip_query2.php?ip={0}", ip.Trim());
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);


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


这篇关于未找到预期的DTD标记。第1行,第3位。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆