日期:2014-05-19  浏览次数:20576 次

写了读取XML函数,但是在一个节点下只能读到一行,请高手看看?
<PARAMETER_SET>
        <GOODS_FLOW_OPERATION>
                <Port_Operation>
                        <Port_Operation_TP   name= "Port_Ex "   value= "0 "   cn= "A "/>
      <Port_Operation_TP   name= "Port_Im "   value= "1 "   cn= "B "/>
                  </Port_Operation>
        </GOODS_FLOW_OPERATION>
</PARAMETER_SET>

private   string   GetXmlPath()
{
              return   Server.MapPath( "../bin/全局参数统一编码.xml ");
}

private   DataTable   CreateDataTable()
{
DataTable   myDataTable   =   new   DataTable();
DataColumn   myDataColumn;

//   Create   new   DataColumn,   set   DataType,   ColumnName   and   add   to   DataTable.        
myDataColumn   =   new   DataColumn();
myDataColumn.DataType   =   System.Type.GetType( "System.String ");
myDataColumn.ColumnName   =   "Text ";
myDataColumn.ReadOnly   =   true;
myDataColumn.Unique   =   false;
//   Add   the   Column   to   the   DataColumnCollection.
myDataTable.Columns.Add(myDataColumn);

//   Create   second   column.
myDataColumn   =   new   DataColumn();
myDataColumn.DataType   =   System.Type.GetType( "System.String ");
myDataColumn.ColumnName   =   "Value ";
myDataColumn.ReadOnly   =   true;
myDataColumn.Unique   =   false;
//   Add   the   column   to   the   table.
myDataTable.Columns.Add(myDataColumn);

return   myDataTable;
}
public   bool   ReadXmlForList(out   DataSet   dsDataSet)
{
dsDataSet   =   new   DataSet();  
try
{
DataTable   dt=   this.CreateDataTable();
DataRow     row;
int i =   0;

m_Xmldoc.Load(m_XmlPath);

XmlNodeList   nodes   =   m_Xmldoc.SelectNodes( "/PARAMETER_SET/GOODS_FLOW_OPERATION/Port_Operation[Port_Operation_TP/@name=   'Port_Ex '   and   Port_Operation_TP/@name=   'Port_Im '] ");

int   j   =   nodes.Count;///////这里读的总是1
foreach   (XmlNode   node   in   nodes)
{
row   =   dt.NewRow();
row[ "Text "]   =   node.ChildNodes[i].Attributes[ "cn "].Value;
row[ "Value "]   =   node.ChildNodes[i].Attributes[ "value "].Value;
dt.Rows.Add(row);
i++;
}
dsDataSet.Tables.Add(dt);
}
catch(System.Exception   ex)
{
return   false;
}
return   true;
}
int   j   =   nodes.Count;///////这里读的总是1
只能取到
<Port_Operation_TP   name= "Port_Ex "   value= "0 "   cn= "A "/>