Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / February 2008

Tip: Looking for answers? Try searching our database.

Root Element is missing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
deepak - 25 Feb 2008 13:46 GMT
Hi All,

i am getting the error "root element is missing in the below code at line  
xdoc.LoadXml(Trim(sxp_message))..Kinldy help me if i need to chnage this
code...This code is giving me correct xml (i checked in quickwatch) and it
seems that it has every thing corrrect then why this error coming.
Is it due to use of Request .InputStream?SHould i need to write these 5-6
top lines(in page load) code in diffrent way?

Kindly tell me please as i am new to .net.If pssoible then tell me by
writing the exact code please as i am stuck here from 2 days.

****************CODE************************************
   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
       Dim smsrequest As New SendRequest
       Dim smsservice As New SmsApiService
       Dim smsresponse As SendResponse

       Dim strmread As StreamReader
       Dim sxp_message As String
       Dim all_message As String
       Dim error_message As String

       Dim sms_text As String
       Dim assign_start As DateTime
       Dim engno As String
       Dim sms_title As String

       Dim xdoc As New XmlDocument
       Dim root As XmlElement
       Dim xnodes As XmlNodeList
       Dim xnode As XmlNode

       Dim username As String
       Dim password As String
       Dim tariff As String
       Dim accname As String
       Dim charFilter As String
       Dim Messagelen As Integer

       Try
           username = Request.Params("USER")
           password = Request.Params("PASSWORD")
           tariff = Request.Params("TARIFF")
           accname = Request.Params("ACCNAME")
           charFilter = Request.Params("CFILTER")
           If charFilter = "" Then ' by default set character filter as OFF
               charFilter = "OFF"
           End If

           strmread = New StreamReader(Request.InputStream)
           sxp_message = strmread.ReadToEnd
           strmread.Close()

           all_message = System.DateTime.Now & vbCrLf & "SXP from Click
IM:" & vbCrLf & sxp_message & vbCrLf
           xdoc.LoadXml(Trim(sxp_message))

           root = xdoc.DocumentElement

           xnodes = root.GetElementsByTagName("Engineer")
           assign_start = root.Item("Assignment").InnerText
           root = root.Item("Task")

           If root Is Nothing Then
               Throw New local_exception("Unable to locate Task tag")
           End If

           sms_text = "ID: " &
root.Item("NOCRefID").InnerText.TrimStart("0") & vbCrLf
           sms_text = sms_text & "Eq.Typ: " &
Trim(root.Item("EquipmentType").InnerText) & vbCrLf
           sms_text = sms_text & "Site: " &
Trim(root.Item("Site").InnerText) & vbCrLf
           sms_text = sms_text & "Prio: " &
Trim(root.Item("Priority").InnerText) & vbCrLf
           sms_text = sms_text & "Start: " & Format(assign_start,
"yyyy-MM-dd HH:mm:ss") & vbCrLf
           sms_text = sms_text & "Act: " &
Trim(root.Item("SubType").InnerText) & vbCrLf

           sms_title = root.Item("Title").InnerText
           If charFilter = "ON" Then
               filterSMSChar(sms_title) ' if character Filter is ON. Filter
SMS title
           End If

           sms_text = sms_text & "Title: " & sms_title

           smsrequest.correlationId = "WFMSMS"
           smsrequest.originatorAlpha = True

           smsrequest.originatingAddress = "WFM"   '"#MSISDN:"
           smsrequest.dcs = 25 'Changed from -1 to 25 for extended
character support
           smsrequest.pid = -1
           smsrequest.relativeValidityTime = -1
           smsrequest.statusReportFlags = -1
           smsrequest.deliveryTime = "#NULL#"
           If accname = "" Then
               smsrequest.accountName = "bronze"    'use bronze channel if
nothing is specified
           Else
               smsrequest.accountName = accname
           End If

           smsrequest.blocking = True
           smsrequest.tariffClass = Trim(tariff)
           smsrequest.referenceId = "#NULL#"
           smsrequest.contentCategory = "#NULL#"
           smsrequest.username = Trim(username)
           smsrequest.password = Trim(password)

           smsservice.Timeout = 60 * 5 * 1000
           smsservice.Proxy = New
System.Net.WebProxy("www-proxy.ericsson.se", 8080)

           For Each xnode In xnodes
               engno = xnode.InnerText
               engno = Replace(engno, "+", "", , , CompareMethod.Text)
               engno = Replace(engno, " ", "", , , CompareMethod.Text)
               engno = engno.TrimStart("0")
               smsrequest.destinationAddress = Trim(engno)
               '-------------------------------------------------------------
               smsservice.RequestEncoding = System.Text.Encoding.Unicode
               smsrequest.userDataHeader = "0500030F"
               Dim no_of_packets As Integer
               Dim sequence_no As Integer
               no_of_packets = Math.Ceiling(sms_text.Length / 68)
               For sequence_no = 1 To no_of_packets
                   smsrequest.userData = Mid(sms_text, (68 * (sequence_no -
1) + 1), 68)
                   smsrequest.userDataHeader = "0500030F" &
no_of_packets.ToString("D2") & sequence_no.ToString("D2")
                   
'-------------------------------------------------------------
                   smsresponse = smsservice.send(smsrequest)
                   If smsresponse.responseCode <> 0 Then
                       Throw New local_exception("IPX response (" &
smsresponse.responseCode & ") " & smsresponse.responseMessage)
                   End If
                   smsrequest.tariffClass = "SEK0"
               Next
           Next
           '-------------------
           all_message = all_message.Concat(all_message, vbCrLf & "Date
time: " & System.DateTime.Now & vbCrLf, "Response from IPX:" & vbCrLf &
smsresponse.responseCode & smsresponse.responseMessage & vbCrLf & vbCrLf)
           '------------------
           write_logs(all_message, "", "SMSContentProviderLog_" &
Format(System.DateTime.Today, "yyyy_MM_dd") & ".txt", "Outbound")
           Response.Write("<MessageResult Status=""1"" />")
       Catch ex As Exception
           error_message = ex.Message
           write_logs(all_message, error_message, "SMSContentProviderLog_"
& Format(System.DateTime.Today, "yyyy_MM_dd") & ".txt", "Outbound")
           Response.Write("<MessageResult Status=""2"" />")
       End Try

   End Sub
   Function filterSMSChar(ByRef sms_title As String)

       Dim titleBuffer As Char
       Dim validChar As String =
"@ΔSP0¡P¿p£_!1AQaq$Φ""2BRbr¥Γ#3CScsèΛ¤4DTdtéΩ%5EUeuùΠ&6FVfvìΨ'7GWgwòΣ(8HXhxÇΘ)9IYiyLFΞ*:JZjzØ1)+;KÄkäøÆ,<LÖlöCRæ-=MÑmñÅß.>NÜnüåÉ/?O§oà|^€{}PB[~]\"
       Dim titleEnum As CharEnumerator
       titleEnum = sms_title.GetEnumerator
       Do While titleEnum.MoveNext
           If validChar.IndexOf(titleEnum.Current) = -1 Then
               sms_title = sms_title.Replace(titleEnum.Current, " ")
           End If
       Loop
   End Function

End Class

*****************code*************************************

Again Thanks in advance and helping me,
Deepak
Martin Honnen - 25 Feb 2008 14:06 GMT
> i am getting the error "root element is missing in the below code at line  
> xdoc.LoadXml(Trim(sxp_message))..Kinldy help me if i need to chnage this
> code...This code is giving me correct xml (i checked in quickwatch) and it
> seems that it has every thing corrrect then why this error coming.
> Is it due to use of Request .InputStream?SHould i need to write these 5-6
> top lines(in page load) code in diffrent way?

>             strmread = New StreamReader(Request.InputStream)
>             sxp_message = strmread.ReadToEnd
[quoted text clipped - 3 lines]
> IM:" & vbCrLf & sxp_message & vbCrLf
>             xdoc.LoadXml(Trim(sxp_message))

Well if LoadXml gives you the error message "root element is missing"
then what you pass in (e.g. Trim(sxp_message)) is not well-formed XML.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

deepak - 25 Feb 2008 14:42 GMT
Hi Martin,

May i use the  code like below which i found from a site..?

strmread = New StreamReader(Request.InputStream)
    'sxp_message = strmread.ReadToEnd
Dim fixedXml = "<root>" + strmread.ReadToEnd() + "</root>"
Dim xmlRdr As New XmlTextReader(New StringReader(fixedXml))
strmread.Close()

all_message = System.DateTime.Now & vbCrLf & "SXP from Click IM:" & vbCrLf
& sxp_message & vbCrLf

 'xdoc.LoadXml(Trim(sxp_message))
 xdoc.Load(xmlRdr)

- Deepak

> > i am getting the error "root element is missing in the below code at line  
> > xdoc.LoadXml(Trim(sxp_message))..Kinldy help me if i need to chnage this
[quoted text clipped - 13 lines]
> Well if LoadXml gives you the error message "root element is missing"
> then what you pass in (e.g. Trim(sxp_message)) is not well-formed XML.
Martin Honnen - 25 Feb 2008 14:58 GMT
> May i use the  code like below which i found from a site..?
>
[quoted text clipped - 9 lines]
>   'xdoc.LoadXml(Trim(sxp_message))
>   xdoc.Load(xmlRdr)

Whether you need to add a root element depends on what you receive in
Request.InputStream. Using an XmlTextReader is however not necessary,
LoadXml suffices to parse a string of XML.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.