Calling web service return utf-16 and cause messy code

Last post 04-28-2008 10:12 AM by SGWellens. 3 replies.

Sort Posts:

  • Calling web service return utf-16 and cause messy code

    04-25-2008, 1:00 AM
    • Member
      3 point Member
    • dream.li
    • Member since 09-12-2007, 3:06 AM
    • Posts 29

    I use asp.net to call a web service, and it return below

    <ResponsePacket xmlns="urn:Microsoft.Search.Response">
        <Response domain="QDomain">
            <Copyright>Microsoft (c) Office SharePoint (tm) Portal Server 2003</Copyright>
            <Range>
                <StartAt>1</StartAt>
                <Count>1000</Count>
                <TotalAvailable>461</TotalAvailable>
                <Results>
                    <Document type="" relevance="569" xmlns="urn:Microsoft.Search.Response.Document">
                        <Title>推荐需求</Title>
                        <Action>
                            <LinkUrl fileExt="aspx" size="0">http://sopapp03.sol.shuion.com.cn/C13/env/Lists/List1/view.aspx</LinkUrl>
                        </Action>
                        <Description>
                            1 上海动物园科普志愿者报名(需求开放中) 2006-03-09T06:39:48Z 2006-03-04T07:18:21Z Kevin Zhou Yun Peng 21 Kevin Zhou Yun Peng 6 -1 0 上海动物园科普志愿者报名(需求开放中) 上海动物园科普志愿者报名(需求开放中) 1 100.000000000000 {4ACF93A3-A5B5-4FEB-82A3-06C1B523726A} <div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000080" size=2>
                        </Description>
                        <Date>2008-04-14T02:31:29</Date>
                    </Document>
                    <Document type="" relevance="561" xmlns="urn:Microsoft.Search.Response.Document">
                        <Title>环境保护</Title>
                        <Action>
                            <LinkUrl size="55669">http://sopapp03.sol.shuion.com.cn/C13/env</LinkUrl>
                        </Action>
                        <Description>
                            帮助 瑞安门户网站  环境保护  当前位置 动作 项目介绍 环境保护已经日益成为我们所关注的话题,生存危机、可持续发展深入到我们每天的生活。瑞安海鸥社将通过一系列的环境保护活动推动我们身边的生活环境、工作环境、生态环境的改善。同时,我们也将组织志愿者参与我们的各项宣传、推广活动,推动社会的可持续发展。  想象一下天蓝草绿水清的世界,我们可以做得更多!  作者  2006-4-4 10:43 4月9日(星期日)上午9:00  大宁灵石公园正门                           2006-3-9 10:20 2006-3-9 14:39 走入绿色,发现亮色!
                        </Description>
                        <Date>2008-03-03T09:18:20</Date>
                    </Document>
        </Results>
            </Range>
            <Status>SUCCESS</Status>
        </Response>
    </ResponsePacket>

     The xml is utf-16 format, as web service is return xml format so I read it and I want its description

      

     string XMLresult=WebService.QueryResult();
      System.Xml.XmlDocument dc = new System.Xml.XmlDocument();
     dc.LoadXml(XMLresult);
       XmlNodeList nodes=dc.SelectNodes("/ResponsePacket/Response/Range/Results/Document");
       foreach (XmlNode node in nodes)
         {
             Response.Write(node["description"]);
         
         }
     
    when I run, It always return nothing, I debug , find nodes count is 0.
    if I open the xml in  vs2008, it give error say "the xml is not formatted",as 
      <Description> æˆ·ç½‘ç«™    您好 IT Portal 瑞安é </Description> contain  #x20 illegal character.
    how to solve this problem
  • Re: Calling web service return utf-16 and cause messy code

    04-25-2008, 8:33 AM
    Answer
    • All-Star
      87,573 point All-Star
    • SGWellens
    • Member since 01-02-2007, 4:27 PM
    • Twin Cities, MN
    • Posts 7,170
    • Moderator
      TrustedFriends-MVPs

    I don't know if your underlying data is corrupt, or it became corrupt when you pasted it into the web page but the XML was malformed with these unbalanced elements:

        <div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000080" size="2">

    After deleting the above, I was able to select the Descriptions with this XPath query:

        //def:Description

    Steve Wellens

    My blog
  • Re: Calling web service return utf-16 and cause messy code

    04-27-2008, 10:38 PM
    • Member
      3 point Member
    • dream.li
    • Member since 09-12-2007, 3:06 AM
    • Posts 29
    Could you write xpath and description code for me? I still un-resole it
  • Re: Calling web service return utf-16 and cause messy code

    04-28-2008, 10:12 AM
    • All-Star
      87,573 point All-Star
    • SGWellens
    • Member since 01-02-2007, 4:27 PM
    • Twin Cities, MN
    • Posts 7,170
    • Moderator
      TrustedFriends-MVPs

     

    Bubba Soft This site has a great free tool for building XPath Expressions (XPath Builder).
    Steve Wellens

    My blog
Page 1 of 1 (4 items)