0

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>
1
  • Well what is ns1? Commented Aug 19, 2015 at 9:43

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.