友人からもらった
http://ideone.com/PLkpym
においてxmldocに結合後のxmlファイルをminidom.parseしていれることで無事期待通りの操作ができました。
python
1xmldoc = xdoc
2#xdocは結合後のファイル.xmlをminidom.parseしてある
3
4newdoc = minidom.getDOMImplementation().createDocument(None, "graphml", None)
5
6'''
7<graphml
8xmlns="http://graphml.graphdrawing.org/xmlns"
9xmlns:java="http://www.yworks.com/xml/yfiles-common/1.0/java"
10xmlns:sys="http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0"
11xmlns:x="http://www.yworks.com/xml/yfiles-common/markup/2.0"
12xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13xmlns:y="http://www.yworks.com/xml/graphml"
14xmlns:yed="http://www.yworks.com/xml/yed/3"
15xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
16'''
17#for yED
18root_node = newdoc.documentElement
19root_node.setAttribute('xmlns', 'http://graphml.graphdrawing.org/xmlns')
20root_node.setAttribute('xmlns:java', 'http://www.yworks.com/xml/yfiles-common/1.0/java')
21root_node.setAttribute('xmlns:sys','http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0')
22root_node.setAttribute('xmlns:x','http://www.yworks.com/xml/yfiles-common/markup/2.0')
23root_node.setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance')
24root_node.setAttribute('xmlns:y','http://www.yworks.com/xml/graphml')
25root_node.setAttribute('xmlns:yed','http://www.yworks.com/xml/yed/3')
26root_node.setAttribute('xsi:schemaLocation','http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd')
27
28
29graphmls = xmldoc.getElementsByTagName('graphml')
30for graphml in graphmls:
31 for child in graphml.childNodes:
32 newdoc.documentElement.appendChild(child.cloneNode(True))
33
34xstr = newdoc.toxml()
35
36
37f = open('newdata2.xml', 'w') #open file with w-mode
38f.write(xstr) #write xstr in the xml
39f.close() #close file
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2015/11/24 18:37
2015/11/28 15:06