简体   繁体   中英

what is the difference between xml code

I have been working on webservice and came across thsi:

What is the difference between:

<string xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://companyx.net/" xsi:nil="true"/>

And

<string xmlns="http://companyx.net/">[]</string>

The reason for asking is because I coded (try) a webservice and if I invoke it I get <string xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://companyx.net/" xsi:nil="true"/> and other web service method I look at returns <string xmlns="http://companyx.net/">[]</string> when invoked. I know the second method returns a array of items, and I need to do that to. I want to return a list of contacts.

My web service code:

 <WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
    Public Function ContactGet(ByVal searchField As String) As String

        Dim objSearch As New ArrayList
        Dim objSearching As New Search
        Dim intResult As Integer

        Try

            intResult = objSearching.SearchByKeyword(searchField, Session("Person"), Session("Office"), Session("Organisation"), _
                                                  Session("Role"), companyx.CXMyProperty.Search.enmSearchType.enmContact, objSearch)


                Dim objContact As New Person
                Dim dt As New DataTable("Contacts")

                Dim col_Name As New DataColumn("Name", GetType(String))
                dt.Columns.Add(col_Name)

                Dim col_Mobile As New DataColumn("Mobile", GetType(String))
                dt.Columns.Add(col_Mobile)

                Dim col_Office As New DataColumn("ContactNum", GetType(String))
                dt.Columns.Add(col_Office)

                Dim col_Category As New DataColumn("Category", GetType(String))
                dt.Columns.Add(col_Category)

                Dim dr As DataRow

                'add new row to datatable
                For Each objSearching In objSearch
                    dr = dt.NewRow()
                    dr("Name") = objContact.FullName
                    dr("Mobile:") = objContact.MobileNumber
                    dr("ContactNum") = objContact.OfficeNumber
                    dr("Category") = objContact.PersonRelationshipType
                    dt.Rows.Add(dr)
                Next

                Dim serializer As New JavaScriptSerializer()
                Dim rows As New List(Of Dictionary(Of String, Object))()
                Dim row As Dictionary(Of String, Object) = Nothing

                'serialize dt row to json output
                For Each drow As DataRow In dt.Rows
                    row = New Dictionary(Of String, Object)()
                    For Each col As DataColumn In dt.Columns
                        row.Add(col.ColumnName, dr(col))
                    Next
                    rows.Add(row)
                Next

                Dim str_json = JsonConvert.SerializeObject(dt, Formatting.Indented)

                Return str_json
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

Im not sure if I coded the web service correctly. Very new to this.

The differences between them are that in one case the string element has an xsi:nil attribute and in the other case it has a "[]" text node child.

These might or might not have similar or identical semantics: you need to ask the folks at companyx.net, who designed this vocabulary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM