XML update issue
Posted: Sun Jul 26, 2009 6:10 pm
I'm building a standalone app that uses local XML files as data storage devices. I'm using the XML stack tutorial as my guide in constructing the methods.
Loading XML files is working fine. Add nodes is working fine. Saving files is working fine.
Updating nodes is not working.
Here are the contents of a test XML file.
<?xml version="1.0"?>
<contactTable>
<contact contactID="adamsalex">
<lastName>Adams</lastName>
<firstName>Alex</firstName>
<middleName/>
<companyName>A2 Technology Partners, Inc.</companyName>
<title>President</title>
<profession>Software Innovator</profession>
</contact>
<contact contactID="adamsnancykrogseng">
<lastName>Adams</lastName>
<firstName>Nancy</firstName>
<middleName>Krogseng</middleName>
<companyName>Nancy-Krogseng Adams PsyD.</companyName>
<title>Licensed Psychologist</title>
<profession>Psychologist</profession>
</contact>
</contactTable>
Here is the update handler code:
on updateRecord
global gvContactID
local lvStart, lvDocID, lvNode, lvChild
local lvContactID, lvLastName, lvFirstName, lvMiddleName, lvCompanyName, lvTitle, lvProfession
-- find the document ID - this routine creates one if there isn't one already
put field "fldDocID" of card 1 of this stack into lvDocID
-- build the full node address for the selected contact record
put "/contactTable/contact[" & gvContactID & "]" into lvNode
put field "fldLastName" of card "crdContactRecord" into lvLastName
put field "fldFirstName" of card "crdContactRecord" into lvFirstName
put field "fldMiddleName" of card "crdContactRecord" into lvMiddleName
put field "fldCompanyName" of card "crdContactRecord" into lvCompanyName
put field "fldTitle" of card "crdContactRecord" into lvTitle
put field "fldProfession" of card "crdContactRecord" into lvProfession
revPutIntoXMLNode lvDocID, lvNode & "/lastName", lvLastName
checkForError the result, " lastname ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/firstName", lvFirstName
checkForError the result, " firstname ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/middleName", lvMiddleName
checkForError the result, " middlename ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/companyName", lvCompanyName
checkForError the result, "c ompanyname ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/title", lvTitle
checkForError the result, " title ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/profession", lvProfession
checkForError the result, " profession ", lvNode
-- setup the display field for text instead of an XML tree
set the tabStops of field "fldContactTree" of card 1 of this stack to 60
put formatXMLtext(lvDocID) into field "fldContactTree" of card 1 of this stack
end updateRecord
Here is the checkForError code:
on checkForError pError, pField, pNode
if word 1 of pError contains "xmlErr" then
answer error pError & pField & pNode as sheet
exit to top
end if
end checkForError
Every time, I get the following result:
xmlerr, can't find element lastname
/contactTable/contact[adamsalex]
What am I doing wrong?
Thanks,
Alex Adams
A2 Technology Partners, Inc.
alex@a2technology.com
Loading XML files is working fine. Add nodes is working fine. Saving files is working fine.
Updating nodes is not working.
Here are the contents of a test XML file.
<?xml version="1.0"?>
<contactTable>
<contact contactID="adamsalex">
<lastName>Adams</lastName>
<firstName>Alex</firstName>
<middleName/>
<companyName>A2 Technology Partners, Inc.</companyName>
<title>President</title>
<profession>Software Innovator</profession>
</contact>
<contact contactID="adamsnancykrogseng">
<lastName>Adams</lastName>
<firstName>Nancy</firstName>
<middleName>Krogseng</middleName>
<companyName>Nancy-Krogseng Adams PsyD.</companyName>
<title>Licensed Psychologist</title>
<profession>Psychologist</profession>
</contact>
</contactTable>
Here is the update handler code:
on updateRecord
global gvContactID
local lvStart, lvDocID, lvNode, lvChild
local lvContactID, lvLastName, lvFirstName, lvMiddleName, lvCompanyName, lvTitle, lvProfession
-- find the document ID - this routine creates one if there isn't one already
put field "fldDocID" of card 1 of this stack into lvDocID
-- build the full node address for the selected contact record
put "/contactTable/contact[" & gvContactID & "]" into lvNode
put field "fldLastName" of card "crdContactRecord" into lvLastName
put field "fldFirstName" of card "crdContactRecord" into lvFirstName
put field "fldMiddleName" of card "crdContactRecord" into lvMiddleName
put field "fldCompanyName" of card "crdContactRecord" into lvCompanyName
put field "fldTitle" of card "crdContactRecord" into lvTitle
put field "fldProfession" of card "crdContactRecord" into lvProfession
revPutIntoXMLNode lvDocID, lvNode & "/lastName", lvLastName
checkForError the result, " lastname ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/firstName", lvFirstName
checkForError the result, " firstname ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/middleName", lvMiddleName
checkForError the result, " middlename ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/companyName", lvCompanyName
checkForError the result, "c ompanyname ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/title", lvTitle
checkForError the result, " title ", lvNode
revPutIntoXMLNode lvDocID, lvNode & "/profession", lvProfession
checkForError the result, " profession ", lvNode
-- setup the display field for text instead of an XML tree
set the tabStops of field "fldContactTree" of card 1 of this stack to 60
put formatXMLtext(lvDocID) into field "fldContactTree" of card 1 of this stack
end updateRecord
Here is the checkForError code:
on checkForError pError, pField, pNode
if word 1 of pError contains "xmlErr" then
answer error pError & pField & pNode as sheet
exit to top
end if
end checkForError
Every time, I get the following result:
xmlerr, can't find element lastname
/contactTable/contact[adamsalex]
What am I doing wrong?
Thanks,
Alex Adams
A2 Technology Partners, Inc.
alex@a2technology.com