3,424
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0"?>
<!DOCTYPE gxl SYSTEM "http://www.gupro.de/GXL/gxl-1.0.dtd">
<gxl>
<graph id="molid180" edgeids="false" edgemode="undirected">
<node id="_1">
<attr name="symbol">
<string>C </string>
</attr>
<attr name="chem">
<int>1</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>3.7321</float>
</attr>
<attr name="y">
<float>1.25</float>
</attr>
</node>
<node id="_2">
<attr name="symbol">
<string>O </string>
</attr>
<attr name="chem">
<int>2</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>4.5981</float>
</attr>
<attr name="y">
<float>1.75</float>
</attr>
</node>
<node id="_3">
<attr name="symbol">
<string>O </string>
</attr>
<attr name="chem">
<int>2</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>2.866</float>
</attr>
<attr name="y">
<float>1.75</float>
</attr>
</node>
<node id="_4">
<attr name="symbol">
<string>C </string>
</attr>
<attr name="chem">
<int>1</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>3.7321</float>
</attr>
<attr name="y">
<float>0.25</float>
</attr>
</node>
<node id="_5">
<attr name="symbol">
<string>C </string>
</attr>
<attr name="chem">
<int>1</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>2.866</float>
</attr>
<attr name="y">
<float>-0.25</float>
</attr>
</node>
<node id="_6">
<attr name="symbol">
<string>C </string>
</attr>
<attr name="chem">
<int>1</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>4.5981</float>
</attr>
<attr name="y">
<float>-0.25</float>
</attr>
</node>
<node id="_7">
<attr name="symbol">
<string>O </string>
</attr>
<attr name="chem">
<int>2</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>2</float>
</attr>
<attr name="y">
<float>0.25</float>
</attr>
</node>
<node id="_8">
<attr name="symbol">
<string>C </string>
</attr>
<attr name="chem">
<int>1</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>2.866</float>
</attr>
<attr name="y">
<float>-1.25</float>
</attr>
</node>
<node id="_9">
<attr name="symbol">
<string>C </string>
</attr>
<attr name="chem">
<int>1</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>4.5981</float>
</attr>
<attr name="y">
<float>-1.25</float>
</attr>
</node>
<node id="_10">
<attr name="symbol">
<string>C </string>
</attr>
<attr name="chem">
<int>1</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>3.732</float>
</attr>
<attr name="y">
<float>-1.75</float>
</attr>
</node>
<edge from="_1" to="_2">
<attr name="valence">
<int>2</int>
</attr>
</edge>
<edge from="_1" to="_3">
<attr name="valence">
<int>1</int>
</attr>
</edge>
<edge from="_1" to="_4">
<attr name="valence">
<int>1</int>
</attr>
</edge>
<edge from="_4" to="_5">
<attr name="valence">
<int>2</int>
</attr>
</edge>
<edge from="_4" to="_6">
<attr name="valence">
<int>1</int>
</attr>
</edge>
<edge from="_5" to="_7">
<attr name="valence">
<int>1</int>
</attr>
</edge>
<edge from="_5" to="_8">
<attr name="valence">
<int>1</int>
</attr>
</edge>
<edge from="_6" to="_9">
<attr name="valence">
<int>2</int>
</attr>
</edge>
<edge from="_8" to="_10">
<attr name="valence">
<int>2</int>
</attr>
</edge>
<edge from="_9" to="_10">
<attr name="valence">
<int>1</int>
</attr>
</edge>
</graph>
</gxl>
<node id="_1">
<attr name="symbol">
<string>C </string>
</attr>
<attr name="chem">
<int>1</int>
</attr>
<attr name="charge">
<int>0</int>
</attr>
<attr name="x">
<float>3.7321</float>
</attr>
<attr name="y">
<float>1.25</float>
</attr>
</node>
from xml.dom.minidom import parse
import xml.dom.minidom
import pandas as pd
file_path = r'gxl1111.xml'
DOMTree = xml.dom.minidom.parse(file_path)
collection = DOMTree.documentElement
#在集合中获取所有顶点
nodes = collection.getElementsByTagName("node")
#用列表存放获取的顶点信息
Node_from = []
Node_symbol = []
for node in nodes:
if node.hasAttribute("id"):
pattern = re.findall(r'(\d)' ,node.getAttribute("id") )
pattern = [str(j) for j in pattern]
pattern = ''.join(pattern)
node_id = pattern
Node_from.append(node_id)
if node.hasAttribute("symbol"):
Node_symbol.append(node.getAttribute("symbol"))
#将列表元素string类型转变为整形
Node_from=list(map(int,Node_from))
print(Node_from)
print(Node_symbol)