Ich habe die folgende XML (ein Teil von .vcxproj in der Tat), um zu überprüfen:lxml: Wie Tag-Wert in verschiedenen Knoten
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Create</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;ELEC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>Create</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ELEC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAsManaged>
</CompileAsManaged>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
Und ich möchte, um alle Daten von ClCompile
oder Link
überprüfen. Ich kann Element bekommen, aber kein spezifisches und verifiziere seinen Wert danach.
Hier ist meine eigentliche Code:
tree = etree.parse(xml)
ns = {'ns': 'http://schemas.microsoft.com/developer/msbuild/2003'}
debug = tree.xpath('//ns:ItemDefinitionGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Release|x64\'"]', namespaces=ns)
for d in debug:
print(d)
for g in d:
print(g)
Und ich habe die folgende Ausgabe:
<Element {http://schemas.microsoft.com/developer/msbuild/2003}ClCompile at 0x7f95a2eb2548>
Level4
Create
MaxSpeed
true
true
WIN32;NDEBUG;_WINDOWS;_USRDLL;ELEC_EXPORTS;%(PreprocessorDefinitions)
false
StreamingSIMDExtensions2
<Element {http://schemas.microsoft.com/developer/msbuild/2003}Link at 0x7f95a2eb25c8>
Windows
true
true
true
No dependencies
Jetzt möchte ich überprüfen, ob Optimization
MaxSpeed
ist und nach etwas tun. Aber ich kann nicht. Wenn ich es versuche:
tree.xpath('//ns:ItemDefinitionGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Release|x64\'"]/ClCompile/Optimization', namespaces=ns)
Es gibt eine leere Liste zurück.
Wie kann ich nur speziell überprüfen Optimization
, für nur ItemDefinitionGroup
mit ?
Vielen Dank für Hilfe.
try [contains (@Condition, '$ (Konfiguration) | $ (Platform) \' == \ Release | Win32 '')] –