Jython or Pyton issue-- Kindly Help me....

Peter Otten __peter__ at web.de
Wed Oct 15 11:04:12 CEST 2014


Venugopal Reddy wrote:

> Thanks for Help Sir,
> 
> Am using " for feature in tree.findall(
>         ".//{urn:ford/interface/VehicleOrder/LegacyFeatureMapping/v2}PortInstalledOptionFeature"):
>         ) "
> 
> Please sir help me
> 
> Here  also  this findall Method is not return any list values.

OK, I tried it:

$ cat xml_werscode.py
from xml.etree import ElementTree as ET

data = """<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
                <c:RetriveByVehicleLineModelYearResponse xmlns:a="urn:ford/VehicleOrder/LegacyFeatureMapping/v2.0" 
xmlns:b="urn:ford/VehicleOrder/SingleOrderEdit/v1.0" xmlns:c="urn:ford/interface/VehicleOrder/LegacyFeatureMapping/v2">
                        <c:PortInstalledOptionFeature>
                                <a:VehicleLineId>13001</a:VehicleLineId>
                                <a:ModelYear>2014</a:ModelYear>
                                <a:LegacyColumn>12</a:LegacyColumn>
                                <a:LegacyValue>178       </a:LegacyValue>
                                <a:SalesCode>W78</a:SalesCode>
                                <a:MappingId>41859</a:MappingId>
                                <a:MappingSeq>0</a:MappingSeq>
                                <a:MappingDirection>B</a:MappingDirection>
                                <a:TargetFeature>
                                        <a:TargetCatgegory>
                                                <a:Id>181</a:Id>
                                                <a:Name>LIGHT TRUCK WHEELBASES        </a:Name>
                                                <a:Type>P</a:Type>
                                                <a:FamilyCode>AA5</a:FamilyCode>
                                        </a:TargetCatgegory>
                                        <a:OrderFeatureId>15615</a:OrderFeatureId>
                                        <a:WersCode>AA5K8</a:WersCode>
                                        <a:OrderFeatureName>178 /4521MM WHEELBASE         </a:OrderFeatureName>
                                        <a:PIO>false</a:PIO>
                                        <a:SummaryFeature>false</a:SummaryFeature>
                                </a:TargetFeature>
                                <a:TargetFeature>
                                        <a:TargetCatgegory>
                                                <a:Id>181</a:Id>
                                                <a:Name>LIGHT TRUCK WHEELBASES        </a:Name>
                                                <a:Type>P</a:Type>
                                                <a:FamilyCode>AA5</a:FamilyCode>
                                        </a:TargetCatgegory>
                                        <a:OrderFeatureId>15615</a:OrderFeatureId>
                                        <a:WersCode>AA5K8_second time</a:WersCode>
                                        <a:OrderFeatureName>178 /4521MM WHEELBASE         </a:OrderFeatureName>
                                        <a:PIO>false</a:PIO>
                                        <a:SummaryFeature>false</a:SummaryFeature>
                                </a:TargetFeature>
                        </c:PortInstalledOptionFeature>
                        <c:PortInstalledOptionFeature>
                                <a:VehicleLineId>13001</a:VehicleLineId>
                                <a:ModelYear>2014</a:ModelYear>
                                <a:LegacyColumn>12</a:LegacyColumn>
                                <a:LegacyValue>190       </a:LegacyValue>
                                <a:SalesCode>W90</a:SalesCode>
                                <a:MappingId>41860</a:MappingId>
                                <a:MappingSeq>0</a:MappingSeq>
                                <a:MappingDirection>B</a:MappingDirection>
                                <a:TargetFeature>
                                        <a:TargetCatgegory>
                                                <a:Id>181</a:Id>
                                                <a:Name>LIGHT TRUCK WHEELBASES        </a:Name>
                                                <a:Type>P</a:Type>
                                                <a:FamilyCode>AA5</a:FamilyCode>
                                        </a:TargetCatgegory>
                                        <a:OrderFeatureId>15616</a:OrderFeatureId>
                                        <a:WersCode>AA5MA</a:WersCode>
                                        <a:OrderFeatureName>190 /4826MM WHEELBASE         </a:OrderFeatureName>
                                        <a:PIO>false</a:PIO>
                                        <a:SummaryFeature>false</a:SummaryFeature>
                                </a:TargetFeature>
                        </c:PortInstalledOptionFeature>
                </c:RetriveByVehicleLineModelYearResponse>
        </soapenv:Body>
</soapenv:Envelope>
"""


tree = ET.fromstring(data)
for feature in tree.findall(
        ".//{urn:ford/interface/VehicleOrder/LegacyFeatureMapping/v2}PortInstalledOptionFeature"):
    code = feature.find(".//{urn:ford/VehicleOrder/LegacyFeatureMapping/v2.0}WersCode")
    print(code.text)
$ python xml_werscode.py 
AA5K8
AA5MA

As you can see I do get the expected output. I am sorry I have no idea what 
you might be doing wrong.




More information about the Python-list mailing list