I'm developing web applications for in-house use and designed to interact with Microsoft's Customer Relationship Management system. The way the CRM API works with respect to retrieving data is that you call the Retrieve method on a proxy object for the type of object you are trying to retrieve, and specify the guid of the actual instance of that object you are interested in.
For example (pseudocode) :
strOutput = oInvoice.Retrieve( user_authorization, invoiceGuid, elements_you_would_like_re
would return an XML string describing the specific invoice who's guid is 'invoiceGuid'. If you leave 'elements_you_would_like_r
eturned', it returns the entire invoice.
HOWEVER (this is the root of my problem), if fields in the invoice object are blank (quite a common occurance), the XML element containing that column's information is missing.
Typically once the XML string is returned, it is loaded into an XmlDocument. If I wish to display the 'Bill To' address, for instance--
xmlDoc.LoadXML(strOutput) 'output from above
textbox1.Text = xmlDoc("invoice").Item("bi
-- but if the billto_city field was left blank, this throws an 'Object reference not set to an instance of object' exception.
It is not really feasable to put this inside a Try-Catch block, as I would need to do this for every column in the Invoice object.
I DO have an xsd which describes the CRM Invoice, however, having done some research, I found at http://www.w3.org/TR/xmlschema-0/
"Default attribute values apply when attributes are missing, and default element values apply when elements are empty." That seems disheartening.
So my question is this: Is there any way to put missing XML elements into the returned string so the application wouldn't throw that exception when I try and print out all the values?
Thanks in advance for any help, and for reading that long and convoluted post.