在windows应用程序中使用此行代码可以得到ROWDATA节点
XmlNode xn=xmlDoc.SelectSingleNode("//DATAPACKET/ROWDATA");
可在PDA模式下却无此方法,不知道有没有可以替换的方法?

解决方案 »

  1.   

    刚刚写好了一个XML的公共类,看看是否适用于你的
    using System;
    using System.Xml;
    using System.IO;
    using System.Text;namespace BaseStationPDA
    {
    /// <summary>
    /// Summary description for XMLAccess.
    /// </summary>
    public class XMLAccess
    {
    public XMLAccess()
    {
    //
    // TODO: Add constructor logic here
    //
    } public static string reader(string strin)
    {
    string strout=string.Empty;

    StringReader strReader = new StringReader(strin);
    XmlTextReader reader = new XmlTextReader(strReader);

    // reader.ReadStartElement();
    // return XmlConvert.ToString(reader.ReadString());
    try
    {
    while (reader.Read())
    {
    switch (reader.NodeType)
    {

    case XmlNodeType.Element: // The node is an element.
    if(reader.Name!="CData")
    strout+=reader.Name;
    while (reader.MoveToNextAttribute()) // Read the attributes.
    {
    strout+=reader.Name+"="+reader.Value+";";
    }
    break;
    case XmlNodeType.Text: //Display the text in each element.
    strout+="="+reader.Value+";";
    while (reader.MoveToNextAttribute()) // Read the attributes.
    {
    strout+=reader.Name+"="+reader.Value+";";
    }
    break;
    case XmlNodeType. EndElement: //Display the end of the element.
    //strout+=reader.Name;
    break;
    }
    }
    }
    catch(IOException ex)
    {
    strout="";
    }
    if(strout.Length>3)
    strout=strout.Substring(0,strout.Length-1);
    return strout;
    } public static string write(string strin)
    {
    string[] strout=strin.Split(';');
    StringWriter wr=new StringWriter();
    XmlTextWriter writer=new XmlTextWriter(wr);
    writer.Formatting=Formatting.Indented; 
    try
    {
            
    //Write an element (this one is the root).
    writer.WriteStartElement("CData");
    for(int i=0;i<strout.Length;i++)
    {
    string[] detail=strout[i].ToString().Split('=');
    //写节点
    // writer.WriteStartElement(detail[0].ToString());
    // writer.WriteString(detail[1].ToString());
    // writer.WriteEndElement();
    //写属性
    writer.WriteAttributeString(detail[0].ToString(),detail[1].ToString());

    }
    //Write the title element.
    //Write the close tag for the root element.
    writer.WriteEndElement();
    }
    catch(IOException ex)
    {
    return ex.Message.ToString();
    }
    writer.Close(); //Write the XML to file and close the writer.
    return wr.ToString();
    }
    public static bool Save( string strin,string directory)
    {
    bool flag=false;
    string[] strout=strin.Split(';');
    FileStream afile=new FileStream(directory,FileMode.OpenOrCreate);
    StreamWriter wr=new StreamWriter(afile);
    XmlTextWriter writer=new XmlTextWriter(wr);
    writer.Formatting=Formatting.Indented; 
    try
    {
            
    //Write an element (this one is the root).
    writer.WriteStartElement("CData");

    for(int i=0;i<strout.Length;i++)
    {
    string[] detail=strout[i].ToString().Split('=');
    writer.WriteStartElement(detail[0].ToString());
    writer.WriteString(detail[1].ToString());
    writer.WriteEndElement();
    }

    writer.WriteEndElement();
    flag=true;
    }
    catch (IOException ex)
    {
    flag=false;
    }
    writer.Close(); //Write the XML to file and c
    return flag;
    }
    public static bool delete(string directory)
    {
    FileInfo fileexis=new FileInfo(directory);
    if(!fileexis.Exists)
    return true;
    try
    {
    File.Delete(directory); }
    catch(IOException ex)
    {
    return false;
    }
    return true; }
    public static string open(string directory)
    {
    string strout=string.Empty;
    FileInfo fileexis=new FileInfo(directory);
    if(!fileexis.Exists)
    return strout="file not exist";
    FileStream afile=new FileStream(directory,FileMode.Open);
    StreamReader strReader = new StreamReader(afile);
    XmlTextReader reader = new XmlTextReader(strReader);

    // reader.ReadStartElement();
    // return XmlConvert.ToString(reader.ReadString());
    try
    {
    while (reader.Read())
    {
    switch (reader.NodeType)
    {

    case XmlNodeType.Element: // The node is an element.
    if(reader.Name!="CData")
    strout+=reader.Name;
    while (reader.MoveToNextAttribute()) // Read the attributes.
    {
    strout+=reader.Name+"="+reader.Value+";";
    }
    break;
    case XmlNodeType.Text: //Display the text in each element.
    strout+="="+reader.Value+";";
    while (reader.MoveToNextAttribute()) // Read the attributes.
    {
    strout+=reader.Name+"="+reader.Value+";";
    }
    break;
    case XmlNodeType. EndElement: //Display the end of the element.
    //strout+=reader.Name;
    break;
    }
    }
    strReader.Close();
    }
    catch(IOException ex)
    {
    strout=ex.Message.ToString();
    }
    if(strout.Length>3)
    strout=strout.Substring(0,strout.Length-1);
    return strout;
    } }
    }
      

  2.   

    调用的方法,我在PDA上试阗有用
    string usermessage=XMLAccess.open("\\user.xml");
    XMLAccess.Save("User="+txtUser.Text.Trim()+";Password="+txtPassword.Text.Trim()+""
    +";checkItem= 基站巡检","\\user.xml");
    string tstr=XMLAccess.write("type=PdaLoginCheckRequest;userId="+User+";longitude="+GpsLongitude +";latitude="+GpsLatitude+";speed="+GpsSpeed+";password="+password);