Parsing XML error

Just got started with eggplant and i want to parse some XML. I have been able to parse simpler XML using the senseTalk xmlParserScript.

I am trying a different method this time and the script works, but only for the first set of child nodes.

my XML looks like this:

tnclTool_pointer tnclTool_eliminate tnclTool_highlighter tnclTool_pencil tnclTool_eraser tnclTool_notepad tnclTool_ruler tnclTool_protractor tnclTool_dot tnclTool_line tnclTool_compass tnclTool_pTable tnclTool_magnifier tnclTool_pointer tnclTool_eliminate tnclTool_highlighter tnclTool_pencil tnclTool_eraser tnclTool_notepad tnclTool_ruler tnclTool_protractor tnclTool_dot tnclTool_line tnclTool_compass

my script:

put file "C:\path_to_the_data_file\data.xml" as a tree into XMLSource
set dataSet to XMLSource

put node "tnLink" of dataSet into tnLinkNode
put tnLinkNode's _attributes.path into testNavLink


put dataSet's _children into itemList

repeat with each item in itemList
	set itemNode to node item of itemList as tree
	put itemNode's _attributes.uin into itemUIN	
	put itemNode's _children into toolList
	
	repeat with each toolImage in toolList
		put the text of toolImage into toolName
		put "toolName:" & toolName
	end repeat
	put
end repeat

so it runs perfect for the first item
prints out the toolName’s as expected but then…

the error message:
24-May-12 12:42:35 FAILURE NSInternalInconsistencyException NSXMLElement.m:432 Assertion failed in NSXMLElement(instance), method insertChild:atIndex:. NSInvalidArgumentException
Execution Time 0:00:00 testNavToolsTest.script

seems to fail the second time this runs:
set itemNode to node item of itemList as tree

Im sure this is a total noob question. I hope someone can help!

thanks

all i wanna do is create a variable that houses that node and all its children in XML so i can continue to parse it.

i know

set itemNode to node item of itemList as tree

is wrong… I have tried a few other ways but they all seem to cause the same error, or not print out any XML at all :frowning:

I changed this

set itemNode to node item of itemList as tree

to this

put item of itemList as tree into itemNode

put “itemNode:” & itemNode

now it prints an empty value

Ok, first thing, remove your “put” at the bottom of your code…

Second, I think, actually pretty sure, even though it looks the same, your XML is formatted wrong. To correct that all I did was build the xml file from eggplant.

set XMLSource to {{


tnclTool_pointer
tnclTool_eliminate
tnclTool_highlighter
tnclTool_pencil
tnclTool_eraser
tnclTool_notepad
tnclTool_ruler
tnclTool_protractor
tnclTool_dot
tnclTool_line
tnclTool_compass
tnclTool_pTable
tnclTool_magnifier


tnclTool_pointer
tnclTool_eliminate
tnclTool_highlighter
tnclTool_pencil
tnclTool_eraser
tnclTool_notepad
tnclTool_ruler
tnclTool_protractor
tnclTool_dot
tnclTool_line
tnclTool_compass


}}

set order to XMLSource as tree

put XMLSource into file “/users/temp/blah2.xml”

then I directed your code “minus your put at the end” to blah2.xml and it returned this…

toolName:tnclTool_pointer
toolName:tnclTool_eliminate
toolName:tnclTool_highlighter
toolName:tnclTool_pencil
toolName:tnclTool_eraser
toolName:tnclTool_notepad
toolName:tnclTool_ruler
toolName:tnclTool_protractor
toolName:tnclTool_dot
toolName:tnclTool_line
toolName:tnclTool_compass
toolName:tnclTool_pTable
toolName:tnclTool_magnifier
toolName:tnclTool_pointer
toolName:tnclTool_eliminate
toolName:tnclTool_highlighter
toolName:tnclTool_pencil
toolName:tnclTool_eraser
toolName:tnclTool_notepad
toolName:tnclTool_ruler
toolName:tnclTool_protractor
toolName:tnclTool_dot
toolName:tnclTool_line
toolName:tnclTool_compass
toolName:tnclTool_pTable
toolName:tnclTool_magnifier

I dunno if that’s what you wanted…but it’s more than just 1 result and no errors.

hmm i just did exactly what you said and im still getting the same error…could you post the suite that you edited to work so i can dig into it.

also…the reason why the XML was an external file is, i will be running this multiple times with different data.
i dont want to have to edit the eggplant code every time i want to update a tool :slight_smile:

Are you running v11.3 of eggPlant? I’ve been running your code with your XML (both the version in your suite and the slightly different version in your post) and it’s been working consistently for me.

So i downloaded and installed the latest version and now the script does less

i have no idea why i am getting a different experience than you.

i am running the 11.3 Windows version.

thanks for helping!

Try changing the first line of your repeat loop from:

set itemNode to node item of itemList as tree 

to

set itemNode to it as tree 

That works consistently for me on eggPlant for Windows.

still no workie for me.

now when this runs > put “itemNode:” & itemNode

I get this in the output:

itemNode:IT
itemNode:IT
itemNode:IT

any chance you could post the working suite here and let me try it?

thanks,

I think maybe you changed something else prior to my suggestion. This code definitely works and consistently produces the correct output:

put file "C:\path_to_the_data_file\data.xml" as a tree into XMLSource
set dataSet to XMLSource

put node "tnLink" of dataSet into tnLinkNode
put tnLinkNode's _attributes.path into testNavLink


put dataSet's _children into itemList

repeat with each item in itemList
   set itemNode to it as tree
   put itemNode's _attributes.uin into itemUIN   
   put itemNode's _children into toolList
   
   repeat with each toolImage in toolList
      put the text of toolImage into toolName
      put "toolName:" & toolName
   end repeat
   put
end repeat

not sure why but i started again and this time was able to get it to work using your line of code!!

thanks very much!!!
:smiley: :smiley: