fork(2) download
  1. import re
  2. import xml.etree.ElementTree as ET
  3.  
  4. content = """<?xml version="1.0" encoding="utf-8"?>
  5. <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  6. <metadata>
  7. <id>AutoMapper</id>
  8. <version>9.0.0</version>
  9. <authors>Jimmy Bogard</authors>
  10. <owners>Jimmy Bogard</owners>
  11. <requireLicenseAcceptance>false</requireLicenseAcceptance>
  12. <licenseUrl>https://g...content-available-to-author-only...b.com/AutoMapper/AutoMapper/blob/master/LICENSE.txt</licenseUrl>
  13. <projectUrl>https://a...content-available-to-author-only...r.org/</projectUrl>
  14. <iconUrl>https://s...content-available-to-author-only...s.com/automapper/icon.png</iconUrl>
  15. <description>A convention-based object-object mapper.</description>
  16. <repository type="git" url="https://g...content-available-to-author-only...b.com/AutoMapper/AutoMapper" commit="53faf3f014802b502f6a49b4c94368f478752f59" />
  17. <dependencies>
  18. <group targetFramework=".NETFramework4.6.1" />
  19. <group targetFramework=".NETStandard2.0">
  20. <dependency id="Microsoft.CSharp" version="4.5.0" exclude="Build,Analyzers" />
  21. <dependency id="System.Reflection.Emit" version="4.3.0" exclude="Build,Analyzers" />
  22. </group>
  23. </dependencies>
  24. <frameworkAssemblies>
  25. <frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.6.1" />
  26. </frameworkAssemblies>
  27. </metadata>
  28. </package>"""
  29.  
  30. if re.search(r'<licenseUrl>(?P<url>.*?)</licenseUrl>', content, flags=re.DOTALL or re.MULTILINE) is not None:
  31. print('<licenseUrl> found using regex')
  32.  
  33. tree = ET.fromstring(content)
  34.  
  35. tag = tree.find('licenseUrl')
  36. if tag is None:
  37. print("tree.find('licenseUrl'): nothing found")
  38.  
  39. tags = tree.findall('*/licenseUrl')
  40. if len(tags) == 0:
  41. print("tree.findall('*/licenseUrl'): nothing found")
  42.  
  43. tags = tree.findall('.//licenseUrl')
  44. if len(tags) == 0:
  45. print("tree.findall('.//licenseUrl'): nothing found")
  46.  
  47. tags = tree.findall('licenseUrl')
  48. if len(tags) == 0:
  49. print("tree.findall('licenseUrl'): nothing found")
  50.  
  51. tag = tree.find('.//{*}licenseUrl')
  52. if tag is None:
  53. print("tree.find('.//{*}licenseUrl'): nothing found")
Success #stdin #stdout 0.03s 64900KB
stdin
Standard input is empty
stdout
<licenseUrl> found using regex
tree.find('licenseUrl'): nothing found
tree.findall('*/licenseUrl'): nothing found
tree.findall('.//licenseUrl'): nothing found
tree.findall('licenseUrl'): nothing found
tree.find('.//{*}licenseUrl'): nothing found