在Python中遍历XML树

时间:2013-02-05 13:24:40

标签: python xml

第二次尝试。

所以使用

>>> for node in tree.iter():
...     print(node.tag)
... 

我得到以下内容。

{http://www.smpte-ra.org/schemas/430-3/2006/ETM}DCinemaSecurityMessage
{http://www.smpte-ra.org/schemas/430-3/2006/ETM}AuthenticatedPublic
{http://www.smpte-ra.org/schemas/430-3/2006/ETM}MessageId
{http://www.smpte-ra.org/schemas/430-3/2006/ETM}MessageType
{http://www.smpte-ra.org/schemas/430-3/2006/ETM}AnnotationText
{http://www.smpte-ra.org/schemas/430-3/2006/ETM}IssueDate
{http://www.smpte-ra.org/schemas/430-3/2006/ETM}Signer
{http://www.w3.org/2000/09/xmldsig#}X509IssuerName
{http://www.w3.org/2000/09/xmldsig#}X509SerialNumber
{http://www.smpte-ra.org/schemas/430-3/2006/ETM}RequiredExtensions
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}KDMRequiredExtensions
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}Recipient
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}X509IssuerSerial
{http://www.w3.org/2000/09/xmldsig#}X509IssuerName
{http://www.w3.org/2000/09/xmldsig#}X509SerialNumber
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}X509SubjectName
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}CompositionPlaylistId
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}ContentTitleText
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}ContentKeysNotValidBefore
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}ContentKeysNotValidAfter
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}AuthorizedDeviceInfo
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}DeviceListIdentifier
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}DeviceList
{http://www.smpte-ra.org/schemas/430-1/2006/KDM}CertificateThumbprint

在第一行,如何在DCinemaSecurityMessage之后查看文本?或任何其他 测试遵循{http://www.smpte-ra.org/schemas/430-1/2006/KDM}?

我正在看的实际xml的一部分是:

我不清楚我如何遍历和存储该信息的某些部分。我是否必须知道某些东西是孩子还是节点,还是我可以正确寻找标识符的for循环,而不是存储它在标识符后面找到的东西?

<?xml version="1.0" encoding="UTF-8" standalone="no" ?><DCinemaSecurityMessage xmlns="http://www.smpte-ra.org/schemas/430-3/2006/ETM" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:enc="http://www.w3.org/2001/04/xmlenc#">
  <!-- Generated by Waimea 0.4.28l (wlib 0.9.53) -->
<AuthenticatedPublic Id="ID_AuthenticatedPublic">
    <MessageId>urn:uuid:0bb31789-de90-4e17-859b-dc771ff97280</MessageId>
    <MessageType>http://www.smpte-ra.org/430-1/2006/KDM#kdm-key-type</MessageType>
    <AnnotationText>CLOUDATLAS_FTR-1_S_EN-EN_51_PRE_2K_20120830_ADC_OV ~ KDM for SM.Dolby256-DSP100-000004d8</AnnotationText>
    <IssueDate>2012-09-28T17:39:53+00:00</IssueDate>
    <Signer>
      <dsig:X509IssuerName>dnQualifier=G4c6KCUZh7AzcyJnMCXbf9GAfAA=,CN=.cc-wm-2336-000020,OU=.cc-ra-1a.s430-2.ca.cinecert.com,O=.ca.cinecert.com</dsig:X509IssuerName>
      <dsig:X509SerialNumber>61638</dsig:X509SerialNumber>
    </Signer>

0 个答案:

没有答案