Java:读取和解析XML文件总是返回null
我尝试读取文档对象的XML文件:Java:读取和解析XML文件总是返回null,java,xml,readxml,Java,Xml,Readxml,我尝试读取文档对象的XML文件: <MCSA_Configuration> <Variables> <python27_path> C:\Python27\python.exe </python27_path> <python32_path> C:\Python32\python.exe </python32_path> <xlrd> xlrd-ok <
<MCSA_Configuration>
<Variables>
<python27_path> C:\Python27\python.exe </python27_path>
<python32_path> C:\Python32\python.exe </python32_path>
<xlrd> xlrd-ok </xlrd>
</Variables>
</MCSA_Configuration>
我总是得到xml\u doc NULL
有人能帮我解决这个问题吗
我总是发现该文件不存在,正在使用:
Document doc=XMLReader.Get_XML_Document(“C:\MCSA\MCSA_config.XML”) 不要只检查
if(file!=null)
检查文件是否存在if(file.exists())
。可能的问题是该路径上不存在文件您的代码工作正常
获取文档后检查条件
if(xml_doc == null)
System.out.println("Doc is null");
else
System.out.println("Doc is not null");
你会得到
单据不为空
当您尝试打印文档时,它将给出输出
[#文档:空]
您可以通过该文档对象执行操作。是否得到
错误:找不到XML文件代码>或堆栈跟踪?检查文件是否存在。如果问题仍然存在,则发布堆栈跟踪。我始终得到该文件不存在的信息,即使用:Document doc=XMLReader.get_XML_Document(“C:\\MCSA\\MCSA_config.XML”);而且文件确实在那里..您是否也可以尝试使用前斜杠,例如XMLReader.Get_XML_Document(“C:/MCSA/MCSA_config.XML”)
听起来像是文件名或文件扩展名中有一个尾随空格没有显示在windows中,文件实际上是MCSA_config.xml.txt
if(xml_doc == null)
System.out.println("Doc is null");
else
System.out.println("Doc is not null");