I have a hard time parsing some simple XML data sent back by CC terminal.
Here's the data given here:
" 0 gt; PLEntryMode & gt; 1 & lt; / PLEntryMode & gt; PLNameOnCard & gt; Fconcans / Frank & lt; / PLNameOnCard & gt; AmountDue & gt; 0 & lt; / AmountDue & gt; & lt; TipAmount & gt; 0
CashBackAmout> 0
MerchantFee> 0 0 Code> dim myXmlDoc New XmlDocument myXmlDoc.Load (r.ExtData) Dim ExpDate string = ReturnXmlValue as (as:
I MyXmlDoc, "ExpDate") is the default nameOnCard string = ReturnXmlValue (as myXmlDoc, "PLNameOnCard")
My method:
< Code> protectedX ReturnXmlValue (Xml.XmlDocument as ByVal myXDoc, String dim retval as string = String.Empty dim node as Xml.XmlNodeList = myXDoc.GetElementsByTagName (field) node isnot nothing then node .Count & gt; Try as ByVal field string); 0 then retval = node.Item (0) .InterText end then retain Exception WriteException (ex) as pre-try Return Retraction End Function Try
On the load of errors xml Doctor is going
Am I not parsing it correctly?
Additional Information
Since it was suggested that I made the null terminators, I had the following change, which is what I hope: MyXmlDoc.Load (test) as the MyXmlDoc New XmlDocument (tested)
dim test string = r.ExtData.Replace (ControlChars.NullChar, String.Empty) Pre> I still got the title that I have mentioned in the title.
What is RXatta, this is the line of data that starts with the highlight I highlighted
Due R. PaymentResponse = posl.PaymentResponse
Which gives me something similar to this:.
< Div class = "post-text" itemprop = "text">
Your string is not valid XML.
XML should have a single root element You have several XML elements at the root level:
& lt; PLCardPresent & gt; 0 & lt; / PLCardPresent & gt; & Lt; PLEntryMode & gt; 1 & lt; / PLEntryMode & gt; & Lt; PLNameOnCard & gt; Frankenstein / Frank & lt; / PLNameOnCard & gt; & Lt; AmountDue & gt; 0 & lt; / AmountDue & gt; & Lt; TipAmount & gt; 0 & lt; / TipAmount & gt; & Lt; CashBackAmout & gt; 0 & lt; / CashBackAmout & gt; & Lt; MerchantFee & gt; 0 & lt; / MerchantFee & gt; & Lt; TAXAMOUNT included & gt; 0 & lt; Includes TAXAMOUNT & gt; & Lt; ExpDate & gt; 1219 & lt; / ExpDate & gt; & Lt; ECRRefNum & gt; 666 & lt; / ECRRefNum & gt;
You can initially fix this by adding a starting original element and finally adding the closing parent element so that it
& lt; Looks like root & gt; & Lt; PLCardPresent & gt; 0 & lt; / PLCardPresent & gt; & Lt; PLEntryMode & gt; 1 & lt; / PLEntryMode & gt; & Lt; PLNameOnCard & gt; Frankenstein / Frank & lt; / PLNameOnCard & gt; & Lt; AmountDue & gt; 0 & lt; / AmountDue & gt; & Lt; TipAmount & gt; 0 & lt; / TipAmount & gt; & Lt; CashBackAmout & gt; 0 & lt; / CashBackAmout & gt; & Lt; MerchantFee & gt; 0 & lt; / MerchantFee & gt; & Lt; TAXAMOUNT included & gt; 0 & lt; Includes TAXAMOUNT & gt; & Lt; ExpDate & gt; 1219 & lt; / ExpDate & gt; & Lt; ECRRefNum & gt; 666 & lt; / ECRRefNum & gt; & Lt; / Root & gt;
Second, note the main difference between two methods
xml.Load (filename); // filename as string xml.LoadXml (xmlcontent); // as the XML string
No comments:
Post a Comment