XML Import - Trouble with single instance of nested object

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
james_richards
Posts: 16
Joined: Mon Dec 30, 2019 5:03 am

XML Import - Trouble with single instance of nested object

Post by james_richards »

I imagine I'm overlooking something really simple here. I've created a test business space to trial out importing XML data and works great when I have multiple child objects but seems to fail when an object only has one.

In the example below I have some CD's in an XML and child object LOCATION to store what rooms they may be in. I'm using version 8.3 and can share my bsv if that is helpful. All the records with more than one LOCATION (and ROOM attribute) are working great. The one with only one LOCATION does not create a ref table entry and no LOCATION is created.

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<CATALOG>
    <CD>
        <TITLE>Empire Burlesque</TITLE>
        <ARTIST>Bob Dylan</ARTIST>
        <COUNTRY>USA</COUNTRY>
        <COMPANY>Columbia</COMPANY>
        <PRICE>10.90</PRICE>
        <YEAR>1985</YEAR>
        <LOCATIONS>
            <LOCATION ROOM="Living Room" SHELF="Test"/>
            <LOCATION>
                <ROOM>Bedroom 1</ROOM>
            </LOCATION>
        </LOCATIONS>
    </CD>
    <CD>
        <TITLE>Hide your heart</TITLE>
        <ARTIST>Bonnie Tyler</ARTIST>
        <COUNTRY>UK</COUNTRY>
        <COMPANY>CBS Records</COMPANY>
        <PRICE>9.90</PRICE>
        <YEAR>1988</YEAR>
        <LOCATIONS>
            <LOCATION>
                <ROOM>Basement</ROOM>
            </LOCATION>
            <LOCATION>
                <ROOM>Den</ROOM>
            </LOCATION>
			<LOCATION ROOM="Car" SHELF="Console"/>
        </LOCATIONS>
    </CD>
    <CD>
        <TITLE>Greatest Hits</TITLE>
        <ARTIST>Dolly Parton</ARTIST>
        <COUNTRY>USA</COUNTRY>
        <COMPANY>RCA</COMPANY>
        <PRICE>9.90</PRICE>
        <YEAR>1982</YEAR>
		<LOCATIONS>
			<LOCATION ROOM="Bedroom 2" SHELF="Bottom"/>
		</LOCATIONS>
    </CD>
	 <CD>
        <TITLE>Garbage Man</TITLE>
        <ARTIST>Oscar</ARTIST>
        <COUNTRY>USA</COUNTRY>
        <COMPANY>Smelly Records</COMPANY>
        <PRICE>1.90</PRICE>
        <YEAR>1985</YEAR>
        <LOCATIONS>
            <LOCATION ROOM="Living Room" SHELF="Test"/>
            <LOCATION>
                <ROOM>Bedroom 1</ROOM>
            </LOCATION>
        </LOCATIONS>
    </CD>

</CATALOG>
james_richards
Posts: 16
Joined: Mon Dec 30, 2019 5:03 am

Re: XML Import - Trouble with single instance of nested object

Post by james_richards »

I see some reads so I'm adding in my test bsv in case anyone feels like having a look. I did notice that there is the PARSE_XML function in the lastest version which may very well be the solution I'll need. Maybe I'll have to download the latest version and see how much work I'll be in for to update existing apps from 8.3.

Anywho linking to the XML test bsv.
https://drive.google.com/file/d/1ymHaxL ... vV54avsV8L
BobK
Posts: 559
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: XML Import - Trouble with single instance of nested object

Post by BobK »

I was able to get this to work and here are the changes I made to do it:

1) In your CD BO, change the attribute name LOCATIONS to LOCATION
2) Even though you CD BO does not have any rules, add WITH VALIDATION to your IMPORT statement
3) In the XML stored in SystemSettings.xmlstring, remove all <LOCATIONS> and </LOCATIONS> tags

Run your Import processes and it should work.
Bob
Post Reply