I'm working with creating an XML file and updating it with new data when I get new entries from a file. The code works fine then I create the XML file with CreateXML but when I load the file with LoadXML and try to add a node it gives me an error. There must be something that I'm missing.
Code: Select all
.
.
.
CheckFile = FileSize(MasterFileXMLFileName)
If CheckFile = -1
LogSomething("Creating XML file")
MasterXML = CreateXML(#PB_Any)
LogSomething("MasterXML = " + MasterXML)
MainNode = CreateXMLNode(RootXMLNode(MasterXML), "Customers")
LogSomething("MainNode = " + MainNode)
Else
LogSomething("Opening current XML file.")
MasterXML = LoadXML(#PB_Any, MasterFileXMLFileName)
StatusCheck = XMLStatus(MasterXML)
If StatusCheck <> 0
LogSomething("Error loading the XML file. XML Status = " + StatusCheck + ". Error at " + XMLErrorLine(MasterXML) + " And Character " + XMLErrorPosition(MasterXML) + ": " + XMLError(MasterXML))
Else
LogSomething("XML File " + MasterFileXMLFileName + " loaded without error.")
EndIf
LogSomething("MasterXML = " + MasterXML)
MainNode = RootXMLNode(MasterXML)
LogSomething("Main Node = " + MainNode)
EndIf
ForEach MasterFile()
PatientNode = XMLNodeFromID(MasterXML, MasterFile()\PSID)
If PatientNode = 0
LogSomething("Adding " + MasterFile()\LastName + ", " + MasterFile()\FirstName + " (" + MasterFile()\PSID + ") to the system.")
; Create the XML node for this person
CustomerDisplayName.s = RemoveString(RemoveString(RemoveString(Proper(MasterFile()\FirstName) + Proper(MasterFile()\LastName), " "),","),".")
Customer = CreateXMLNode(MainNode, CustomerDisplayName)
If Customer = 0
LogSomething("Error creating XML node: " + Customer)
EndIf
SetXMLAttribute(Customer, "id", MasterFile()\PSID)
Item = CreateXMLNode(Customer, "LastName")
SetXMLNodeText(Item, Proper(MasterFile()\LastName))
If Not (MasterFile()\LastName = #Empty$ Or MasterFile()\LastName = #Null$)
.
.
.
Code: Select all
.
.
.
FormatXML(MasterXML, #PB_XML_ReFormat | #PB_XML_ReIndent, 2)
SaveXML(MasterXML, MasterFileXMLFileName)
.
.
.
Any help would be much appreciated.
Sincerely,
Steving