After deserializing the XML file I printed the whole data in a message box next to it I used write line activity. At write line activity it was showing an “Object reference not set to an instance of an object error”. Here is the attached file for reference. samplexaml.zip (6.3 KB)
Could anyone suggest, please
Your workflow looks good except that in case of xmls like any other tool the processor requires the namespace of the element to identify the correct element.
What you need to do.
Create a variable ns of type XNamespace and set it default value to “http://www.portalfiscal.inf.br/nfe” which is your xmls default namespace
In the write line where you are using .Element(“nfeProc”) you need to actually use .Element(ns+“nfeProc”)… like this for all your element.
Your writeline: Doc.Element(xs+"nfeProc").Element(xs+"NFe").Element(xs+"infNFe").Elements(xs+"ide").Count.ToString
XML elements in a file need to be uniquely identified to avoid issues when you have same type of elements but they differ in usage (say ID of SAP and ID of Oracle. Both are same elements but belong to different classes/instances).
To do that there is a standard of using namespaces.
Namespaces can be single(when you do just xmlns) like in your case or many(when you use prefix xmlns:ns1).
So when you are using the .Element structure you are basically the processor that this is the path(xpath or xml-path) to the element that i want. nfeProc/NFe/infNFe/ide Its like a folder structure.
Now that there is a namespace for your elements that is defined in the parent element you will need to prefix that for the elements otherwise it will not be able to identify it and thus gives you the error “Object reference not set to an instance of an object error” because its empty.
Please close this thread marking the answer as a solution to this thread.
Thanks, Nadim. I have another small doubt regarding queues and transactions. I am able to retrieve the single item from Get Transaction Item activity (item.Specificcontent(“fieldname”). Can I do the same thing using Get Queues item activity if so could you plz let me know what is the command to get the item.
Actually When you will use GetQueuItems you will get the list of items that you want to extract and then you can iterate through the and get the required data out of each.
Well you dont have to worry if they are different. You just need declare it like we do in case of processing xmls.
Create the various namespaces with the prefix you desire and then use them in the expression like i have mentioned.