我过去在上周运行这个文件,结果非常完美,但今天突然不行了,我没有对它做任何更改。 你能帮我吗
这是我的python代码:
from lxml import etree
import numpy as np
#Parsing the xml file and creating lists
tree = etree.parse("AnyConv.com__CCSOPM Section 1_Master (1).xml")
root = tree.getroot()
Lista = []
tags = []
#Get the unique tags values
for element in root.iter():
Lista.append(element.tag)
tags = np.unique(Lista)
#Show the unique tag[attributes] pairs
for tag in tags:
print(tag,root.xpath(f'//{tag}')[0].attrib.keys())
#Changes the tag name to the comply365's tag's name
for p in tree.findall(".//sect1"):
p.tag = ("section")
for p in tree.findall(".//sect1"):
p.tag = ("section")
for p in tree.findall(".//informaltable"):
p.tag = ("table")
#Modify the tag's attributes to its desired form
for cy in root.xpath('//section'):
cy.attrib['xmlns']='http://www.w3.org/2001/XMLSchema-instance'
cy.attrib['id']='123'
cy.attrib['type']='policy'
cy.attrib['xsi']='urn:fontoxml:cpa.xsd:1.0'
for t in root.xpath('//title'):
t.attrib['id']='123456789'
for p in root.xpath('//para'):
p.attrib['id']='987654321'
for p in root.xpath('//table'):
p.attrib['id']='11111'
for ct in root.xpath('//concept'):
ct.attrib.pop("id", None)
#Print the new xml to make sure it worked:
#print(etree.tostring(root).decode())
tree.write("Resultado de tags XML-COMPLY365.xml")
这现在导致:
OSError: Error reading file 'AnyConv.com__CCSOPM Section 1_Master (1).xml': failed to load external entity "AnyConv.com__CCSOPM Section 1_Master (1).xml"
如果你对如何解决这个问题有任何想法,请随时发表评论
(1)
文件名中的部分表示您已经AnyConv.com__CCSOPM Section 1_Master .xml
文件,然后 再次尝试将具有此名称的文件复制到您的组件还要注意,文件名在
(1)
之前包含一个空格,这是 奇怪的这反过来又表明您的“第一个”文件的名称 (没有(1)
)以空格结尾(这很奇怪)验证文件是否确实存在。 或者将其名称更改为
AnyConv.com__CCSOPM Section 1_Master.xml
,即:(1)
。 然后在代码中相应地更改文件名李>还要注意,文件名包含一个双下划线,这也是一种奇怪的做法。 验证您的文件名中的下划线是否实际为双下划线
在计算机中保留许多同名文件(带有“数字 后缀“在它的名字里)也是一个坏习惯。 更糟糕的做法是在代码中引用这些“重复”的文件。 将文件名更改为没有此类“数字后缀”的文件名(在此 case
(1)
)并将代码中的文件名设置为相同还有一个提示:无论文件名是什么:
F2
键,打开此文件名的版本,但到目前为止 标记的文本不包括文件扩展名(在本例中 “.xml”)Ctrl-A
将文本标记扩展到整个名称 (带扩展名)李>Ctrl-C
将文件名复制到剪贴板Esc
关闭文件名的版本Ctrl-V
将其替换为剪贴板内容李>现在,在代码中,您将获得实际的文件名
还要检查包含此文件的目录是否在列表中 试图打开文件时Python扫描的目录的数目
相关问题 更多 >
编程相关推荐