0

I have a xml file with the data from a maya file using the minidom from xml. i am trying to create a sqllite database using the xml.

<?xml version="1.0" encoding="utf-8"?>
<Data>
    <object id="Car:Wheels_GRP">
        <Car:FrontWheels_GRP type="transform">
            <Car:Wheel_Front_L_GRP type="transform">
                <Car:Wheel_Rim_Front_L_MSH type="transform">
                    <Car:Wheel_Rim_Front_L_MSHShape type="mesh"/>
                    <Car:polySurfaceShape4 type="mesh"/>
                </Car:Wheel_Rim_Front_L_MSH>
                <Car:Wheel_Front_L_MSH type="transform">
                    <Car:Wheel_Front_L_MSHShape type="mesh"/>
                    <Car:polySurfaceShape5 type="mesh"/>
                </Car:Wheel_Front_L_MSH>
            </Car:Wheel_Front_L_GRP>
            <Car:Wheel_Front_R_GRP type="transform">
                <Car:Wheel_Rim_Front_R_MSH type="transform">
                    <Car:Wheel_Rim_Front_R_MSHShape type="mesh"/>
                    <Car:polySurfaceShape6 type="mesh"/>
                </Car:Wheel_Rim_Front_R_MSH>
                <Car:Wheel_Front_R_MSH type="transform">
                    <Car:Wheel_Front_R_MSHShape type="mesh"/>
                    <Car:polySurfaceShape7 type="mesh"/>
                </Car:Wheel_Front_R_MSH>
            </Car:Wheel_Front_R_GRP>
            <Car:Axle_Front_MSH type="transform">
                <Car:Axle_Front_MSHShape type="mesh"/>
                <Car:polySurfaceShape8 type="mesh"/>
            </Car:Axle_Front_MSH>
        </Car:FrontWheels_GRP>
        <Car:BackWheels_GRP type="transform">
            <Car:Wheel_Back_L_GRP type="transform">
                <Car:Wheel_Rim_Back_L_MSH type="transform">
                    <Car:Wheel_Rim_Back_L_MSHShape type="mesh"/>
                    <Car:polySurfaceShape9 type="mesh"/>
                </Car:Wheel_Rim_Back_L_MSH>
                <Car:Wheel_Back_L_MSH type="transform">
                    <Car:Wheel_Back_L_MSHShape type="mesh"/>
                    <Car:polySurfaceShape10 type="mesh"/>
                </Car:Wheel_Back_L_MSH>
            </Car:Wheel_Back_L_GRP>
            <Car:Wheel_Back_R_GRP type="transform">
                <Car:Wheel_Rim_Back_R_MSH type="transform">
                    <Car:Wheel_Rim_Back_R_MSHShape type="mesh"/>
                    <Car:polySurfaceShape11 type="mesh"/>
                </Car:Wheel_Rim_Back_R_MSH>
                <Car:Wheel_Back_R_MSH type="transform">
                    <Car:Wheel_Back_R_MSHShape type="mesh"/>
                    <Car:polySurfaceShape12 type="mesh"/>
                </Car:Wheel_Back_R_MSH>
            </Car:Wheel_Back_R_GRP>
            <Car:Axle_Back_MSH type="transform">
                <Car:Axle_Back_MSHShape type="mesh"/>
                <Car:polySurfaceShape13 type="mesh"/>
            </Car:Axle_Back_MSH>
        </Car:BackWheels_GRP>
    </object>
</Data>

but when i am trying to read it using the code

from xml.dom import minidom
xmldoc = minidom.parse('D:/test.xml')
itemlist = xmldoc.getElementsByTagName('object')
print(len(itemlist))

i keep getting the error xml.parsers.expat.ExpatError: unbound prefix: line 4, column 2

any suggestion as how to read and create a sql database.

1 Answer 1

0

The unbound prefix error is raised because the Car namespace is not defined in the xml.

Make this change to fix the problem:

<object id="Car:Wheels_GRP" xmlns:Car="http://schemas.blah.org">

The namespace url can be anything, but it must be included in the xml.

For converting the xml to a database, check this post:

populating data from xml file to a sqlite database using python

Sign up to request clarification or add additional context in comments.

2 Comments

yes that works fine.. but seems its better to remove the namespace when creating the sql database. So i changed the xml as <Data> <object id="Car:Wheels_GRP"> <transform name="Car:FrontWheels_GRP"> <transform name="Car:Wheel_Front_L_GRP">
Will check how to create a sql database. Thanks for your help.

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.