Skip to content Skip to sidebar Skip to footer

How To Retrieve Xsi:nonamespaceschemalocation From Xml With Lxml?

I am trying to validate XML based on xsi:noNamespaceSchemaLocation. I researched this question but it doesn't seem any available solutions for it. My XML file looks this way:

Solution 1:

Thanks to @mzjn for pointing out about Clark notation.

The solution I came up with is:

from lxml import etree

...

it = etree.fromstring(xml)
# We need to go through all keys since they can be in# Clark notation and have URL with brackets as a prefixfor attr in it.attrib:
    if'noNamespaceSchemaLocation' in attr:
        xsd = it.attrib.get(attr)
        break

...

# Do validations based on XSD URL value

Post a Comment for "How To Retrieve Xsi:nonamespaceschemalocation From Xml With Lxml?"