I built a web server that answers to a form sending IOS app called “Formentry”.
I can’t figure out why the app crashes when the XML response I send comes from a xmlDocument.ToString. If I use a constant to store the request’s response then it works fine.
Exemple :
My XML response looks like that :
<?xml version="1.0" encoding="UTF-8"?>
id
nom
nip
1
Roger
1606
2
Claude
1234
3
Rose
4567
If you prefer…
<?xml version="1.0" encoding="UTF-8"?>
....
id
nom
nip
1
Roger
1606
Code to send response inspveh() is the method creating the XML response it returns a xmldocument constant is a string constant containing the same XML as the one produced by inspveh()
Using inspveh() : FAIL The app crashes
Dim strXml As String
strXml = DefineEncoding(inspvehImport(Request).ToString, Encodings.UTF8)
Request.Header("Content-Type") ="text/html; charset=utf-8"
Request.Print(strXml)
Return True
)
Using constant : SUCCESS the internal database is updated
I forgot to say that we have a PHP little program that actually does the job but we need to build new PHP files for any new form we create. Since I’m not familiar with PHP, I’d rather have a webserver made with Xojo…
I assume the app crashes with an XMLException. If so, you’re doing something wrong with the XMLDocument. Break that part out into a separate project and test it, so you can see what’s happening.
Loannis: that’s just silly. The variable is used immediately and within scope. And even so, it couldn’t cause a crash.
You are right, the strXml is not out of scope and is apparently identical to the constant. If I paste both of them side by side, there is no difference. The only difference between them is that one is contained in a constant and the other is generated by a method that returns an XMLDocument from which I extract the content by using “.to string”. I really can’t figure it out…
Did you examine them byte by byte? There could be non-printable characters embedded in it. And so you’re saying that the crash is not an xmlexception? Then what is it?
And, I agree with you about the fact that it could be an exception that was causing the crash…
But I can’t find why…
1- Sending a constant string value works
2- Sending a string variable doesn’t work but doesn’t make the app crash
3- Sending XMLDocument.toString crashes the app…
Have you run it in the debugger to see whether it’s an exception or a flat out crash? The debugger will break on an exception, or at least display a message.
And I believe that IF you have the same string, it should not make any difference whether it is a constant or a string variable. You can test that by simple setting your string variable to the constant and returning that.
Dim strXml As String
strXml = constant
Request.Header("Content-Type") = "text/html; charset=utf-8
Request.Print(strXml)
Return True
[quote=265400:@Roger St-Arneault]And, I agree with you about the fact that it could be an exception that was causing the crash…
But I can’t find why…
1- Sending a constant string value works
2- Sending a string variable doesn’t work but doesn’t make the app crash
3- Sending XMLDocument.toString crashes the app…
What might be different between these?[/quote]
would need to compare them byte by byte but there HAS to be some differences
Still on that… Tried something else but got the same result… The response taken from the constant works and the one from xmlDocument.print transferred to the strXML variable doesn’t.
The two captures show the binary version of the two Request responses. The text version is the following :
<?xml version="1.0" encoding="UTF-8"?>
id
nom
nip
1
Roger
1606
2
Claude
1234
3
Justin
4567
As you can see, they are both the same. The only odd thing is the dot added to the date (indicated by the arrow) which is not in the text version. What is it? It doesn’t seem to matter since it is present in both the constant and the strXML variable. Is that a valid way to compare those two strings?
and it worked… I don’t know what to conclude… The XML produced by my method seems to be responsible for the problem… But how? When I copy the text result in the constant it works but when I take it directly from XmlDocument.ToString, it doesn’t…
Correction, the result in a constant doesn’t work either…
Here is the method with french annotations …
//Paramtres
Dim dTableName_1 As String = "employes" //Nom de la table de destination des donnes
//Vrifie connexion la BD
Dim db As New PostgreSQLDatabase
db.Host = "xx.xx.xx.xx"
db.Port = 5432
db.DatabaseName = "webservertest"
db.UserName = "xxxxxxxx"
db.Password = "xxxxxxxx"
If db.Connect Then
//Charger les donnes requises : employs
Dim strSQL As String = "SELECT * FROM " + dTableName_1
Dim pgps As PostgreSQLPreparedStatement = db.Prepare(strSQL)
Dim RS As RecordSet = pgps.SQLSelect
//Gnrer le fichier XML
Dim xmlDataDoc As New XmlDocument
//Balise Database
Dim root As XmlNode
root = xmlDataDoc.AppendChild(xmlDataDoc.CreateElement("database"))
//*******Table employs
Using Xojo.Core
Dim d As xojo.Core.Date = xojo.Core.Date.Now
Dim gmt As New xojo.Core.TimeZone(0)
Dim gmtDate As New xojo.Core.Date(d.SecondsFrom1970, gmt)
Dim di As New DateInterval
di.Days = 1
Dim updatedDate As xojo.Core.Date = gmtDate + di
Dim table As XmlNode
table = root.AppendChild(xmlDataDoc.CreateElement("table"))
table.SetAttribute("id", dTableName_1)
table.SetAttribute("updated", updatedDate.ToText + " +0000")
//Titres de colonnes
Dim head As XmlNode
head = table.AppendChild(xmlDataDoc.CreateElement("thead"))
//Crer un rang
Dim rang As XmlNode
rang = head.AppendChild(xmlDataDoc.CreateElement("tr"))
//Titres des colonnes
Dim titre1 As XmlNode //Titre 1
titre1 = rang.AppendChild(xmlDataDoc.CreateElement("th"))
titre1.SetAttribute("type", "id")
titre1.AppendChild(xmlDataDoc.CreateTextNode("id"))
Dim titre2 As XmlNode //Titre 2
titre2 = rang.AppendChild(xmlDataDoc.CreateElement("th"))
titre2.SetAttribute("type", "String")
titre2.AppendChild(xmlDataDoc.CreateTextNode("nom"))
Dim titre3 As XmlNode //Titre 3
titre3 = rang.AppendChild(xmlDataDoc.CreateElement("th"))
titre3.SetAttribute("type", "String")
titre3.AppendChild(xmlDataDoc.CreateTextNode("nip"))
//Donnes
Dim body As XmlNode
body = table.AppendChild(xmlDataDoc.CreateElement("tbody"))
If RS <> Nil And Not (RS.BOF And RS.EOF) Then
While Not RS.EOF
Dim rangData As XmlNode
rangData = body.AppendChild(xmlDataDoc.CreateElement("tr"))
Dim data1 As XmlNode //Donne 1
data1 = rangData.AppendChild(xmlDataDoc.CreateElement("td"))
data1.AppendChild(xmlDataDoc.CreateTextNode(RS.Field("id").StringValue))
Dim data2 As XmlNode //Donne 2
data2 = rangData.AppendChild(xmlDataDoc.CreateElement("td"))
data2.AppendChild(xmlDataDoc.CreateTextNode(RS.Field("nom").StringValue))
Dim data3 As XmlNode //Donne 3
data3 = rangData.AppendChild(xmlDataDoc.CreateElement("td"))
data3.AppendChild(xmlDataDoc.CreateTextNode(RS.Field("nip").StringValue))
RS.MoveNext
Wend
Return xmlDataDoc
End If
Else
Return Nil
End If
As for cars, the problem is often behind the wheel…
Maybe I have a clue… I used Paw to call the PHP file that prepares the xml string. I copied the Request response (text format) in the constant and it works… Now I remember that’s how I made it work.