에 값을 사전에 내가 각 태그의 속성을 가진 XML을 가지고에 다음변환 XML 태그
<?xml version= "1.0" encoding="ISO-8859-1" ?>
<month xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="my.xsd">
<day Day="2016-1-01">
<hour Hour="00:00">
<Variables>
<a>211.3</a>
<b>78.94</b>
<c>0.6</c>
</Variables>
</hour>
<hour Hour="12:00">
<Variables>
<a>155.5</a>
<b>85.5</b>
<c>0.42</c>
</Variables>
</hour>
</day>
</month>
나는 XML을 구문 분석하고 사전에 변환 찾고 있지만 태그, 속성 값.
>>> print d['2016-1-01']['12:00']['b']
>>> 85.5
실제 XML도 더 많은 일 시간이 있습니다
나는 비슷한을 할 수있는 방법을 의미한다. 이것이 가능한가? this answer와 유사한 어떤 기능이 있습니까
# Day
for child_day in root:
print child_day.tag, child_day.attrib
# Hour
for child_hour in child_day:
print '\t', child_hour.tag, child_hour.attrib
# Variables
for child_Variables in child_hour:
print '\t\t', child_Variables.find('b').text
:
내가 할 수 있었던 것을 그것을 구문 분석 할 수있는 유일한 방법은 이것입니다,하지만 당신은 다른 시간에 여러 가지 변수에 대한보고 싶지 어려운 경우 태그 대신이 속성 케이스와 동일한 속성을 사용합니까?
간단히 완벽하게! 나는 너의 설명으로 훨씬 더 나은 사전을 정말로 이해한다. 고맙습니다. – iblasi
문제가 없습니다! 다행스럽게 도울 수있어! – SalmonMode