digitaldrew
Well-known member
- Joined
- Nov 10, 2012
- Messages
- 167
- Programming Experience
- Beginner
I'm having some troubles passing XML through TCP/IP. I've tried doing this two ways and both times I get "Root element is missing"
Here is the XML I am trying to pass:
At first I thought I would try building the XML and then passing it..so I just created each of the elements and attributes manually
After trying it and receiving the missing root error I looked at xml.OuterXML and noticed the <?xml version="1.0" encoding="UTF-8" standalone="no"?> was missing. That's when I decided to try making a string and including it, then passing it that way:
Still got the same error... Any ideas? Here is my code to connect and pass the XML..
Here is the XML I am trying to pass:
At first I thought I would try building the XML and then passing it..so I just created each of the elements and attributes manually
VB.NET:
Dim xml As New System.Xml.XmlDocument()
Dim root As XmlElement
root = xml.CreateElement("epp")
xml.AppendChild(root)
Dim xmlns As XmlAttribute = xml.CreateAttribute("xmlns")
xmlns.Value = "urn:ietf:params:xml:ns:epp-1.0"
root.SetAttributeNode(xmlns)
Dim auth As XmlElement
auth = xml.CreateElement("command")
root.AppendChild(auth)
Dim login As XmlElement
login = xml.CreateElement("login")
auth.AppendChild(login)
Dim username As XmlElement
username = xml.CreateElement("clID")
username.InnerText = loginID
login.AppendChild(username)
Dim pass As XmlElement
pass = xml.CreateElement("pw")
pass.InnerText = password
login.AppendChild(pass)
Dim options As XmlElement
options = xml.CreateElement("options")
login.AppendChild(options)
Dim version As XmlElement
version = xml.CreateElement("version")
version.InnerText = "1.0"
options.AppendChild(version)
Dim lang As XmlElement
lang = xml.CreateElement("lang")
lang.InnerText = "en"
options.AppendChild(lang)
Dim svcs As XmlElement
svcs = xml.CreateElement("svcs")
login.AppendChild(svcs)
Dim objURI1 As XmlElement
objURI1 = xml.CreateElement("objURI")
objURI1.InnerText = "urn:ietf:params:xml:ns:contact-1.0"
svcs.AppendChild(objURI1)
Dim objURI2 As XmlElement
objURI2 = xml.CreateElement("objURI")
objURI2.InnerText = "urn:ietf:params:xml:ns:host-1.0"
svcs.AppendChild(objURI2)
Dim objURI3 As XmlElement
objURI3 = xml.CreateElement("objURI")
objURI3.InnerText = "urn:ietf:params:xml:ns:domain-1.0"
svcs.AppendChild(objURI3)
Dim svcExtension As XmlElement
svcExtension = xml.CreateElement("svcExtension")
svcs.AppendChild(svcExtension)
Dim extURI As XmlElement
extURI = xml.CreateElement("extURI")
extURI.InnerText = "http://rxsd.domain-registry.nl/sidn-ext-epp-1.0"
svcExtension.AppendChild(extURI)
After trying it and receiving the missing root error I looked at xml.OuterXML and noticed the <?xml version="1.0" encoding="UTF-8" standalone="no"?> was missing. That's when I decided to try making a string and including it, then passing it that way:
VB.NET:
Dim post As String = "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?><epp xmlns=""urn:ietf:params:xml:ns:epp-1.0""><command><login><clID>" & loginID & "</clID><pw>" & password & "</pw><options><version>1.0</version><lang>en</lang></options><svcs><objURI>urn:ietf:params:xml:ns:contact-1.0</objURI><objURI>urn:ietf:params:xml:ns:host-1.0</objURI><objURI>urn:ietf:params:xml:ns:domain-1.0</objURI><svcExtension><extURI>http://rxsd.domain-registry.nl/sidn-ext-epp-1.0</extURI></svcExtension></svcs></login><clTRID>300100</clTRID></command></epp>"
Still got the same error... Any ideas? Here is my code to connect and pass the XML..
VB.NET:
Dim client As New TcpClient("drs.registry.nl", 700)
Dim ns As NetworkStream = client.GetStream
If ns.CanRead And ns.CanWrite Then
Dim sendBytes As Byte() = Encoding.UTF8.GetBytes(post)
ns.Write(sendBytes, 0, sendBytes.Length)
Dim responseBytes(client.ReceiveBufferSize) As Byte
ns.Read(responseBytes, 0, CInt(client.ReceiveBufferSize))
Dim xResponse As XmlDocument
xResponse = New XmlDocument
xResponse.LoadXml(Encoding.UTF8.GetString(responseBytes))
MsgBox(Encoding.UTF8.GetString(responseBytes))
Else
MsgBox("Cannot Write to Stream (Login)")
Return False
End If