Elementtree find metódusát megzavarják a namesapcek

0 votes
asked May 25, 2013 in IRF tantárgy by anonymous  

Sziasztok

A wsman által vissza adott xml-t szeretném beparsolni ElementTree segítségével, de a find metódust a NameSpace-k tönkre vágják

Az XML a következő

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:n="http://schemas.xmlsoap.org/ws/2004/09/enumeration" xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xml:lang="hu-HU">
  <s:Header>
    <a:Action>http://schemas.xmlsoap.org/ws/2004/09/enumeration/PullResponse</a:Action>
    <a:MessageID>uuid:561031AF-873B-43B0-A08F-9BF34DCDA813</a:MessageID>
    <a:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:To>
    <a:RelatesTo>uuid:0433ae5a-dd88-1d88-8003-e3bd8f290c00</a:RelatesTo>
  </s:Header>
  <s:Body>
    <n:PullResponse>
      <n:Items>
        <p:Win32_ConnectionShare xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/Win32_ConnectionShare" xmlns:cim="http://schemas.dmtf.org/wbem/wscim/1/common" xsi:type="p:Win32_ConnectionShare_Type">
          <p:Antecedent>
            <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
            <a:ReferenceParameters>
              <w:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/Win32_Share</w:ResourceURI>
              <w:SelectorSet>
                <w:Selector Name="Name">Share</w:Selector>
                <w:Selector Name="__cimnamespace">root/cimv2</w:Selector>
              </w:SelectorSet>
            </a:ReferenceParameters>
          </p:Antecedent>
          <p:Dependent>
            <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
            <a:ReferenceParameters>
              <w:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/Win32_ServerConnection</w:ResourceURI>
              <w:SelectorSet>
                <w:Selector Name="ComputerName">10.6.22.102</w:Selector>
                <w:Selector Name="ShareName">Share</w:Selector>
                <w:Selector Name="UserName">71203</w:Selector>
                <w:Selector Name="__cimnamespace">root/cimv2</w:Selector>
              </w:SelectorSet>
            </a:ReferenceParameters>
          </p:Dependent>
        </p:Win32_ConnectionShare>
      </n:Items>
      <n:EndOfSequence/>
    </n:PullResponse>
  </s:Body>
</s:Envelope>

Az ezt feldolgozó kód:

#! /usr/bin/env python3

import xml.etree.ElementTree as ET

tree=ET.parse("baba-1.xml")

root=tree.getroot()    

body=root.find("{http://www.w3.org/2003/05/soap-envelope}:Body")
print(body)

find("Body")-ra és a fent szereplő kódra None-t add vissza, ha pedig find('s:Body') val kódolom KeyError-t kapok.

2 Answers

0 votes
answered May 25, 2013 by eff (85 points)  
commented May 25, 2013 by anonymous  
És hogy installáltad az lxml-t?

Én a sudo zypper install python-lxml paranccsal próbáltam. Látszólag fel is tette, de az importra hibát dob :/
commented May 25, 2013 by anonymous  
install python3-lxml már működik :)
0 votes
answered Jun 2, 2013 by anonymous  

Nem kell az a kettőspont.

...