Reputation: 1
Below is the XML that I am trying to parse, but it is giving me the error:
xml.etree.ElementTree.ParseError: unbound prefix: line 2, column 0
This is the XML:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:NWEnv>
<name>lk</name>
<gateways>
<IPAddress>1.2.3.2</IPAddress>
</gateways>
<DNSServers>
<IPAddress>1.2.4.3</IPAddress>
</DNSServers>
<doesOverride>false</doesOverride>
<auditUpload>0</auditUpload>
</ns1:NWEnv>
Upvotes: 0
Views: 583
Reputation: 5895
Your xml has an error. The ns1:
prefix is not bound to a namespace. There should be a namespace declaration in your xml using the xmlns attribute.
When using prefixes in XML, a so-called namespace for the prefix must be defined. The namespace is defined by the xmlns attribute in the start tag of an element. The namespace declaration has the following syntax. xmlns:prefix="URI".
Source: http://www.w3schools.com/xml/xml_namespaces.asp
The xml will parse when you define the namespace for the ns1:
prefix. The following parses:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:NWEnv xmlns:ns1="http://put.what.you.like.here.org/nwenv">
<name>lk</name>
<gateways>
<IPAddress>1.2.3.2</IPAddress>
</gateways>
<DNSServers>
<IPAddress>1.2.4.3</IPAddress>
</DNSServers>
<doesOverride>false</doesOverride>
<auditUpload>0</auditUpload>
</ns1:NWEnv>
Upvotes: 1