Foxtable(狐表)用户栏目专家坐堂 → 解析webservice返回的xml


  共有3981人关注过本帖树形打印复制链接

主题:解析webservice返回的xml

帅哥哟,离线,有人找我吗?
ycwk
  21楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1220 积分:8483 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2017/5/11 11:00:00 [只看该作者]

都要显示啊,我要把结果插到表里,output.show只是检验哪地方有问题。有问题的时候table就会为空白,而且不只这一个结果,可能传参以后,返回结果是正常的,也不能正常不正常一概不显示吧
[此贴子已经被作者于2017/5/11 11:00:53编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  22楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/5/11 11:12:00 [只看该作者]

Dim ret As String = FileSys.ReadAllText("g:\xml.txt", encoding.default)
Dim xo As XObject = XObject.Parse(HTMLDecode(ret))

For Each ds As JToken In  xo("NewDataSet")("ds")
    '  output.show( ds("LISITEMNAME"), ds("RESULT"),ds("RANGE"),CStr(ds("FLAG") )
   
    output.show( ds("RANGE"))
   
    output.show( ds("FLAG"))
   
    output.show( ds("LISITEMNAME"))
   
    output.show(ds("RESULT"))
    If Typeof ds("UNIT") Is jvalue Then
        output.show(ds("UNIT"))
    Else
        msgbox(ds("UNIT")("@xml:space"))
    End If
Next


 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  23楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1220 积分:8483 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2017/5/11 11:39:00 [只看该作者]

用下面这段代码,表格死活没有值,大部分项目是正常的,我没整了。

'点击跳转到显示明细页面
Dim e As RequestEventArgs = args(0)
Dim wb As New weui
'msgbox("edit页面")

 '  For Each key As String In e.GetValues.Keys         '可以弹出   seqno: 253514
 '          msgbox(key & ":" & e.GetValues(key))
 '  Next

If e.GetValues.ContainsKey("seqno") =True Then
  'msgbox(e.GetValues("seqno"))  可以弹出
  Dim str_seqno As String = e.GetValues("seqno")
  'Dim PrimaryKey As Integer = e.GetValues("key")
  'Dim PageURL = "List.htm?page=" & PageNumber
  'If e.PostValues.Count = 0 Then '生成编辑页面
  '  Dim dr As DataRow = DataTables("订单").SQLFind("[_Identify]=" & PrimaryKey)
  '  If dr IsNot Nothing Then
       ' wb.AddForm("","form1","edit.htm?key=" & PrimaryKey &  "&page=" & PageNumber)

    Dim str4 As String = "http://10.27.1.1:8085/Service.asmx/Query?queryxml=<root><queryid>QueryReportDetail</queryid><args1>" & str_seqno & "</args1></root>"      
    Dim hc As New HttpClient(str4)
    Dim ret As String = hc.GetData()      
    Dim xo As XObject = XObject.Parse(HTMLDecode(ret))


 If Typeof xo("NewDataSet")("ds")  Is jarray Then          '如果是数组    即 有多行结果用如下代码.    
     With wb.AddTable("","Table1")
        .head.AddRow("项目名称","检查结果","范围","标志","单位") '主表的表头
         For Each ds As JToken In  xo("NewDataSet")("ds")    
          ' .body.AddRow( CStr(ds("LISITEMNAME")), CStr(ds("RESULT")),CStr(ds("RANGE")),CStr(ds("FLAG")),CStr(ds("UNIT")) )    
           If Typeof ds("UNIT") Is jvalue Then
               msgbox(cstr(ds("LISITEMNAME")) & cstr(ds("RESULT")) & cstr(ds("RANGE")) & cstr(ds("FLAG")) & cstr(ds("UNIT")) )
               .body.AddRow( ds("LISITEMNAME"),ds("RESULT"),ds("RANGE"),ds("FLAG"),ds("UNIT"))      
           Else
               msgbox( cstr(ds("LISITEMNAME")) & cstr(ds("RESULT")) & cstr(ds("RANGE")) & cstr(ds("FLAG")) & cstr(ds("UNIT")("@xml:space='preserve'")) )
               .body.AddRow( ds("LISITEMNAME"),ds("RESULT"),ds("RANGE"),ds("FLAG"),ds("UNIT")("@xml:space='preserve'"))         '过滤掉中间的  <UNIT xml:space="preserve">  解析时就报错
           End If         
         Next
    End With 
 Else           '如果不是数组,即呆有一行结果.
    With wb.AddTable("","Table1")
        .head.AddRow("项目名称","检查结果","范围","标志","单位") '主表的表头
        ' For Each ds As JToken In  xo("NewDataSet")("ds")    
          ' .body.AddRow( CStr(ds("LISITEMNAME")), CStr(ds("RESULT")),CStr(ds("RANGE")),CStr(ds("FLAG")),CStr(ds("UNIT")) )      
           .body.AddRow( xo("NewDataSet")("ds")("LISITEMNAME"), xo("NewDataSet")("ds")("RESULT"),xo("NewDataSet")("ds")("RANGE"),xo("NewDataSet")("ds")("FLAG"),xo("NewDataSet")("ds")("UNIT"))      ' '注意如果主表只有一项并没有明细,则这里会报错
        ' Next
    End With 
 End If 

End If

e.WriteString(wb.Build) '生成网页

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  24楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/5/11 12:12:00 [只看该作者]

 我这样测试没问题

 

        Dim wb As New weui
        Dim ret As String = FileSys.ReadAllText("g:\xml.txt", encoding.default)
        Dim xo As XObject = XObject.Parse(HTMLDecode(ret))
       
        If Typeof xo("NewDataSet")("ds")  Is jarray Then          '如果是数组    即 有多行结果用如下代码.
            With wb.AddTable("","Table1")
                .head.AddRow("项目名称","检查结果","范围","标志","单位") '主表的表头
                For Each ds As JToken In  xo("NewDataSet")("ds")
                    ' .body.AddRow( CStr(ds("LISITEMNAME")), CStr(ds("RESULT")),CStr(ds("RANGE")),CStr(ds("FLAG")),CStr(ds("UNIT")) )
                    If Typeof ds("UNIT") Is jvalue Then
                        'msgbox(cstr(ds("LISITEMNAME")) & cstr(ds("RESULT")) & cstr(ds("RANGE")) & cstr(ds("FLAG")) & cstr(ds("UNIT")) )
                        .body.AddRow(ds("LISITEMNAME").tostring,ds("RESULT").tostring,ds("RANGE").tostring, ds("FLAG").tostring ,ds("UNIT").tostring)
                    Else
                        'msgbox( cstr(ds("LISITEMNAME")) & cstr(ds("RESULT")) & cstr(ds("RANGE")) & cstr(ds("FLAG")) & cstr(ds("UNIT")("@xml:space='preserve'")) )
                        .body.AddRow(ds("LISITEMNAME").tostring,ds("RESULT").tostring,ds("RANGE").tostring,ds("FLAG").tostring,ds("UNIT")("@xml:space").tostring)         
                    End If
                Next
            End With
        Else           '如果不是数组,即呆有一行结果.
            With wb.AddTable("","Table1")
                .head.AddRow("项目名称","检查结果","范围","标志","单位") '主表的表头
                ' For Each ds As JToken In  xo("NewDataSet")("ds")
                ' .body.AddRow( CStr(ds("LISITEMNAME")), CStr(ds("RESULT")),CStr(ds("RANGE")),CStr(ds("FLAG")),CStr(ds("UNIT")) )
                .body.AddRow( xo("NewDataSet")("ds")("LISITEMNAME"), xo("NewDataSet")("ds")("RESULT"),xo("NewDataSet")("ds")("RANGE"),xo("NewDataSet")("ds")("FLAG"),xo("NewDataSet")("ds")("UNIT"))      ' '注意如果主表只有一项并没有明细,则这里会报错
                ' Next
            End With
        End If
       
        ' wb.AppendHTML("<script src='./lib/test.js'></script>") '引入脚本文件
        e.WriteString(wb.Build) '生成网页


 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  25楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1220 积分:8483 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2017/5/11 14:45:00 [只看该作者]

加了.tostring依然没有

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  26楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/5/11 15:19:00 [只看该作者]

24楼,测试没问题。请自行认真测试。

 回到顶部
总数 26 上一页 1 2 3