In XML, the element name is defined by the developer, and when two different documents use the same element name, a naming conflict occurs, and the XML namespace provides a way to avoid element naming conflicts.
The XML namespace attribute is placed in the start tag of the element and uses the following syntax:
xmlns:namespace-prefix= "NamespaceURI"
When a namespace is defined in the start tag of an element, all child elements with the same prefix are associated with the same namespace.
Note: The address used to mark the namespace is not used by the parser to find information. Its only function is to give the namespace a unique name.
In addition to explicit definitions, defining a default namespace for an element allows us to omit the work of using prefixes in all child elements. This means that all tags without a prefix will have a default namespace
Please use the following syntax:
Xmlns= "NamespaceURI"
When parsing an XML file with namespaces, be aware that the name of the tag is a combination of a namespace and a label, such as the following XML file:
<?xml version= ' 1.0 ' encoding= ' UTF-8 '? ><NVD xmlns:vuln= "Http://bulabula" xmlns:cvss= "Http://abulaabula" xmlns= "Http://alulalula" > <entry id= "cve-2011-0001" > <vuln:cvss> <cvss:base_ metrics> <cvss:score>5.0</cvss:score> </cvss:base_metrics> </vuln:cvss> </entry></nvd>
Where the default namespace is xmls, two namespaces Xmlns:vuln and Xmlns:cvss are also declared. If you use Python's ElementTree parsing, the following code is wrong
Node.find (' score '). Text
When running, the error will be as follows:
Attributeerror: ' Nonetype ' object has no attribute ' text '
In other words, Node.find (' score ') did not find any results.
The correct way to access this should be to add a namespace:
Cvss = "{Http://abulabula}" Node.find (Cvss + ' score ')
For examples of entry that do not have an explicit prefix, they are implicitly prefixed with xmlns, so the value of xmlns should be added when accessing
XML namespaces and Python parsing methods