Last post Mar 13, 2013 03:14 PM by Laplain
Feb 22, 2013 08:34 PM|Laplain|LINK
I've been doing all kinds of searches today and can't seem to find one clear answer on this.
Our payment gateway posts xml data to a custom URL we set, and when an event is triggered at their business center website, it sends an xml report to the URL.
I can't seem to figure out (or get working) reading the http posted data when my URL is triggered. I can get it to work if I just paste the samle xml data into doc.load("<sample.....>...."), but not if I'm reading the inputstream (or at least I think I
am). I don't have a lot of experience with XML, other than using XML Reader to read through a string, etc.
Here's what I think it chokes at with an exception of "Data at the root level is invalid. Line 1, position 1.". I say "think" because I can't debug this since I have to use their Test button on the custom URL at their website, and I don't want to open up
my local host where I normally test/debug.
Dim requestStream As Stream = Request.InputStream <---I THINK IT CHOKES HERE
Dim xmlDoc As XmlDocument = New XmlDocument
Dim xmlUpdateNodeList, xmlFollowOnNodeList As XmlNodeList
Dim xmlNode As XmlNode
' create XmlNodeReader for document
Dim reader As XmlNodeReader = New XmlNodeReader(xmlDoc)
' display each node's content
Select Case reader.NodeType
' if Element, display its name
xmlString = "<" & reader.Name & ">" & "<br />"
' if empty element, decrease depth
If reader.IsEmptyElement Then
xmlString = "Empty Element" & "<br />"
Case XmlNodeType.Comment ' if Comment, display it
xmlString = "<!--" & reader.Value & _
"-->" & "<br />"
Case XmlNodeType.Text ' if Text, display it
xmlString = reader.Value & "<br />"
' if XML declaration, display it
xmlString = "<?" & reader.Name & " " & _
reader.Value & "?>" & "<br />"
' if EndElement, display it and decrement depth
xmlString = "</" & reader.Name & ">" & "<br />"
Feb 23, 2013 03:26 AM|Talal Tayyab|LINK
This error is indicative of malformed xml. You can try saving the stream data and examining the xml to see if it is proper.
var stream = new StreamReader(Request.InputStream);
var data = stream.ReadToEnd();
Mar 13, 2013 12:01 AM|Laplain|LINK
Mar 13, 2013 03:14 PM|Laplain|LINK
Here's what I get:
Data at the root level is invalid. Line 1, position 1.