xmlHttp:=CreateOleObject('Msxml2.XMLHTTP');
xmlHttp.open('POST',URL,false);
xmlHttp.send('<ns:login xmlns:ns="http://wlpt.soft.com/client/user/dto/xml"><loginInfo><userName>'+p+'</userName><passWord>'+f+'</passWord></loginInfo></ns:login>');
responseText:=xmlHttp.responseText;
stream.Write(responseText,length(responseText));
stream.Position:=0;
xml.LoadFromstream(stream);
Root := xml.DocumentElement;
parent_node:=root.ChildNodes.First;
Child_Node:= Parent_Node.ChildNodes.First ;
ud:=strtoint(Child_Node.Text);
Parent_Node := Root.ChildNodes.last ;
Child_Node:= Parent_Node.ChildNodes.last;
child_node:=child_node.PreviousSibling;
流能正常读出数据。运行无错误提示。但执行程序时报错。有错误字符或数据为空。无法正常解析。请问是XMLDOCUMENT控件的问题嘛?应该如何解决

解决方案 »

  1.   

    var xmlDom,xmlError;
      ....
      xmlDom = new XMLDoc(xmlHttp.responseText, xmlError);
      ...
      

  2.   

    这个跟控件能不能读出流流没有关系"有错误字符或数据为空。无法正常解析"这个应该是说你下载的xml有问题的你可以在xml.LoadFromstream(stream);这句话之前执行
    stream.savetofile('d:\xml.xml'); // 保存完后看xml.xml文件格式是否正确,可以用别的xml解析其打开看有没有错误
    stream.clear;
    xml.loadfromfile('d:\xml.xml'); // 如果这个也出错,就应该和能不能读流没关系了楼主也自己多想想办法测试一下,程序是死的,人是活的~~~
      

  3.   

    我用SAVETOFILE把流中数据保存到硬盘上发现是乱码。
    难道是因为这个问题嘛?
    应该怎么样解决呢?
    谢谢楼上
      

  4.   

    xmlhttp默认返回UTF-8编码的文字流,如果服务器上作了指定,那就返回服务器指定的编码格式,Delphi的string是ANSI格式,从系统组件返回字符串的时候尽量使用WideString。
      

  5.   

    xmlHttp.responseXML直接返回xml格式的
      

  6.   

    嗯。
    是直接返回的是XML格式
    但要怎么样把它解析呢。
    XMLDOCUMENT。LOADFROMFILE(RESPONSE)??
    好像行不通吧
      

  7.   

    xmldocument := xmlhttp.responsexml 这样就行了吧,没试过,楼主试下
      

  8.   

    使用UTF8Decode或者Utf8ToAnsi将xmlHttp.responseText解码,
      

  9.   

    是解码的问题嘛?
    我用的是UTF8的XML
    用XML。LOADFROMFILE(‘X:/XML。XML’);
    这样是能读取UTF8的XML~
      

  10.   

    乱码有可能是中文的问题,用widestring试下
      

  11.   

    嗯。现在感觉是不是字符串过长的问题
    是不是只能读取255。所以当读取的时候会读不全XML??
    会不会呢。?
    用ANSISTRING的话也不能完全把一个超过255的字符存入STRING
    是这个》??
      

  12.   

    把responseText声明成WideString,后面stream.Write部分也相应改一下,再试试看。注意,如果是string类型写入stream,你的写法stream.Write(responseText,length(responseText));是有错误的, string类型不能直接作为指针地址,如果要简便,请用一下写法stream.Write(responseText[1],length(responseText));把string当数组处理。
    这也是你savetofile是乱码的缘故。
      

  13.   

    看看下面的内容
    http://www.knowsky.com/tag-6.htmlXml: OleVarient;
    ...
    xml := CreateOleObject('Msxml2.DOMDocument');xml := xmlhttp.responsexml;
      

  14.   

    这样。。
    我现在用了XMLDOCUMENT。XML。TEXT
    这个把返回信息存入XML控件中。
    这样能正常解析。
    但出现的是如果判断为假的话。
    就是说输入的用户名和密码是错误的话。程序是正确的。能正常的解析。
    但如果输入的用户名和密码是正确的话。程序报错。无法解析。
    都是同一服务器返回的XML。不应该是XML的错吧
    是什么原因呢。
      

  15.   

    还是把xml保存下来,然后看看xml文件是不是对的
      

  16.   

    stream.Write(responseText,length(responseText));错了
    改成stream.Write(responseText[1],length(responseText));
      

  17.   

    xmlHttp:=CreateOleObject('Msxml2.XMLHTTP');
    xmlHttp.open('POST',URL,false);
    xmlHttp.send('<ns:login xmlns:ns="http://wlpt.soft.com/client/user/dto/xml"><loginInfo><userName>'+p+'</userName><passWord>'+f+'</passWord></loginInfo></ns:login>');
    responseText:=xmlHttp.responseText;
    stream.Write(responseText[1],length(responseText));
    stream.Position:=0;
    stream.SaveToFile('C:\FromStream.txt');//从流存出一个文件
    stream.Position:=0;
    xml.LoadFromstream(stream);
    xml.SaveToFile('C:\FromXMLDoc.txt');//从TXMLDocument存出一个文件看看存下来的俩文件是不是正常,这样就知道问题可能处在哪个部分了。