Python读取xml文件总是报错,小白,求解答

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python读取xml文件总是报错,小白,求解答相关的知识,希望对你有一定的参考价值。

C:\Users\ytd\PycharmProjects\sript\venv\Scripts\python.exe C:/Users/ytd/PycharmProjects/sript/xml_Reader/Get_NodeAttribute.py
Traceback (most recent call last):
File "C:/Users/ytd/PycharmProjects/sript/xml_Reader/Get_NodeAttribute.py", line 2, in <module>
dom=minidom.parse('Class_info.xml')
File "C:\Users\ytd\AppData\Local\Programs\Python\Python36-32\lib\xml\dom\minidom.py", line 1958, in parse
return expatbuilder.parse(file)
File "C:\Users\ytd\AppData\Local\Programs\Python\Python36-32\lib\xml\dom\expatbuilder.py", line 911, in parse
result = builder.parseFile(fp)
File "C:\Users\ytd\AppData\Local\Programs\Python\Python36-32\lib\xml\dom\expatbuilder.py", line 207, in parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: XML declaration not well-formed: line 1, column 20

这种一般直接看最后一行:
xml.parsers.expat.ExpatError: XML declaration not well-formed: line 1, column 20
XML声明格式不正确,第1行第20列(第20个字符),你自己按这个信息去检查。
参考技术A 你问的问题就有问题

C# 接收 java webservices接口返回的Byte[] 数组时,大于90M报错System.OutOfMemoryException 求高手解答

捕捉到 System.OutOfMemoryException
HResult=-2147024882
Message=引发类型为“System.OutOfMemoryException”的异常。
Source=mscorlib
StackTrace:
在 System.Text.StringBuilder.set_Length(Int32 value)
在 System.Xml.XmlTextReaderImpl.ParseText()
在 System.Xml.XmlTextReaderImpl.ParseElementContent()
在 System.Xml.XmlTextReaderImpl.Read()
在 System.Xml.XmlTextReader.Read()
在 System.Xml.XmlTextReaderImpl.InitReadElementContentAsBinary()
在 System.Xml.XmlTextReaderImpl.ReadElementContentAsBase64(Byte[] buffer, Int32 index, Int32 count)
在 System.Xml.XmlTextReader.ReadElementContentAsBase64(Byte[] buffer, Int32 index, Int32 count)
在 System.Xml.Serialization.XmlSerializationReader.ReadByteArray(Boolean isBase64)
在 System.Xml.Serialization.XmlSerializationReader.ToByteArrayBase64(Boolean isNull)
在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderLWFDService.Read15_getGRIB2DataResponse()
在 Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer15.Deserialize(XmlSerializationReader reader)
在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
在 System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
在 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

                BasicHttpBinding bind = new System.ServiceModel.BasicHttpBinding(BasicHttpSecurityMode.None);
                bind.AllowCookies = true;
                bind.OpenTimeout = new TimeSpan(0, 0, 60);
                bind.CloseTimeout = new TimeSpan(0, 0, 60);
                bind.SendTimeout = new TimeSpan(0, 0, 300);
                bind.ReceiveTimeout = new TimeSpan(0, 0, 300);
                bind.MaxReceivedMessageSize = int.MaxValue;//这几个属性设置一下,或者你可以设置为long.MaxValue
                bind.ReaderQuotas.MaxStringContentLength = int.MaxValue;//这几个属性设置一下
                bind.ReaderQuotas.MaxDepth = int.MaxValue;//这几个属性设置一下
                bind.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;//这几个属性设置一下
                EndpointAddress address = new EndpointAddress(url);

                //像下面这样实例化你的C# webservice代理类
                 YourProxyClient svcClient = new YourProxyClient(bind, address);追问

我的webservice接口类里没有(bind, address)实例化传这两个参数的构造方法。

追答

那是因为你添加服务引用的方式不对

追问

我就是这样添加的。

追答

不能吧,我每次都有啊,不管是调用的C#还是Java的websevice都能生成这样的代理类。

参考技术A 你这个不能一次系读取,要分段或分包读取!!追问

但是webservices接口就是一次返回所有的BYTE[] 数组,怎么分段读取呢?

以上是关于Python读取xml文件总是报错,小白,求解答的主要内容,如果未能解决你的问题,请参考以下文章

c++,gdal,GCPs报错求解答!

python的quantile函数问题,求解答

python 读取配置文件总是报错 configparser.NoSectionError: No section:

Eclipse创建Maven工程总是出现pom.xml报错怎么办

前端小白想问,jsp?后面是啥意思,怎么用?求大神解答

python读取xml文件报错ValueError: multi-byte encodings are not supported