本文整理匯總了C#中System.Xml.XmlDataDocument.GetRowFromElement方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDataDocument.GetRowFromElement方法的具體用法?C# XmlDataDocument.GetRowFromElement怎麽用?C# XmlDataDocument.GetRowFromElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlDataDocument
的用法示例。
在下文中一共展示了XmlDataDocument.GetRowFromElement方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string connStr = "Data Source=.\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI;";
using (SqlConnection conn = new SqlConnection(connStr))
{
SqlCommand command = new SqlCommand("select * from customers", conn);
conn.Open();
DataSet ds = new DataSet();
ds.DataSetName = "Customers";
ds.Load(command.ExecuteReader(), LoadOption.OverwriteChanges, "Customer");
//Response.ContentType = "text/xml";
//ds.WriteXml(Response.OutputStream);
//Added in Listing 13-15
XmlDataDocument doc = new XmlDataDocument(ds);
doc.DataSet.EnforceConstraints = false;
XmlNode node = doc.SelectSingleNode(@"//Customer[CustomerID = 'ANATR']/ContactTitle");
node.InnerText = "Boss";
doc.DataSet.EnforceConstraints = true;
DataRow dr = doc.GetRowFromElement((XmlElement)node.ParentNode);
Response.Write(dr["ContactName"].ToString() + " is the ");
Response.Write(dr["ContactTitle"].ToString());
}
}
示例2: getObjectList
/// <summary>
/// Возвращает массив объектов по структуре SysObject
/// </summary>
/// <returns></returns>
public ArrayList getObjectList()
{
ArrayList arrField = new ArrayList();
SysObject sObject;
DataSet DS = new DataSet();
try
{
GetXMLFileData(DS, Config_Protocol);
}
catch (Exception e)
{
string sError = e.Message;
}
DataRow row;
XmlDataDocument XDoc = new XmlDataDocument(DS);
XmlNodeList ProtocolNode = XDoc.DocumentElement.SelectNodes("//objects/obj");
foreach (XmlNode xmlNode in ProtocolNode)
{
row = XDoc.GetRowFromElement((XmlElement)xmlNode);
if (row != null)
{
sObject.Index= Convert.ToInt16(row[0].ToString());
sObject.Type = row[1].ToString();
arrField.Add(sObject);
}
}
return arrField;
}
示例3: NewInstance
public void NewInstance ()
{
XmlDataDocument doc = new XmlDataDocument ();
AssertDataSet ("#1", doc.DataSet, "NewDataSet", 0, 0);
Assert.IsFalse (doc.DataSet.EnforceConstraints);
XmlElement el = doc.CreateElement ("TEST");
AssertDataSet ("#2", doc.DataSet, "NewDataSet", 0, 0);
Assert.IsNull (doc.GetRowFromElement (el));
doc.AppendChild (el);
AssertDataSet ("#3", doc.DataSet, "NewDataSet", 0, 0);
DataSet ds = new DataSet ();
doc = new XmlDataDocument (ds);
Assert.IsTrue (doc.DataSet.EnforceConstraints);
}
示例4: GetRowFromElement
public void GetRowFromElement()
{
XmlDataDocument doc = new XmlDataDocument();
doc.DataSet.ReadXmlSchema(new StringReader(RegionXsd));
doc.Load(new StringReader(RegionXml));
XmlElement root = doc.DocumentElement;
DataRow row = doc.GetRowFromElement((XmlElement)root.FirstChild);
Assert.Equal("1", row[0]);
row = doc.GetRowFromElement((XmlElement)root.ChildNodes[2]);
Assert.Equal("3", row[0]);
}
示例5: TestCreateElementAndRow
public void TestCreateElementAndRow ()
{
DataSet ds = new DataSet ("set");
DataTable dt = new DataTable ("tab1");
dt.Columns.Add ("col1");
dt.Columns.Add ("col2");
ds.Tables.Add (dt);
DataTable dt2 = new DataTable ("child");
dt2.Columns.Add ("ref");
dt2.Columns.Add ("val");
ds.Tables.Add (dt2);
DataRelation rel = new DataRelation ("rel",
dt.Columns [0], dt2.Columns [0]);
rel.Nested = true;
ds.Relations.Add (rel);
XmlDataDocument doc = new XmlDataDocument (ds);
doc.LoadXml ("<set><tab1><col1>1</col1><col2/><child><ref>1</ref><val>aaa</val></child></tab1></set>");
AssertEquals (1, ds.Tables [0].Rows.Count);
AssertEquals (1, ds.Tables [1].Rows.Count);
// document element - no mapped row
XmlElement el = doc.DocumentElement;
AssertNull (doc.GetRowFromElement (el));
// tab1 element - has mapped row
el = el.FirstChild as XmlElement;
DataRow row = doc.GetRowFromElement (el);
AssertNotNull (row);
AssertEquals (DataRowState.Added, row.RowState);
// col1 - it is column. no mapped row
el = el.FirstChild as XmlElement;
row = doc.GetRowFromElement (el);
AssertNull (row);
// col2 - it is column. np mapped row
el = el.NextSibling as XmlElement;
row = doc.GetRowFromElement (el);
AssertNull (row);
// child - has mapped row
el = el.NextSibling as XmlElement;
row = doc.GetRowFromElement (el);
AssertNotNull (row);
AssertEquals (DataRowState.Added, row.RowState);
// created (detached) table 1 element (used later)
el = doc.CreateElement ("tab1");
row = doc.GetRowFromElement (el);
AssertEquals (DataRowState.Detached, row.RowState);
AssertEquals (1, dt.Rows.Count); // not added yet
// adding a node before setting EnforceConstraints
// raises an error
try {
doc.DocumentElement.AppendChild (el);
Fail ("Invalid Operation should occur; EnforceConstraints prevents addition.");
} catch (InvalidOperationException) {
}
// try again...
ds.EnforceConstraints = false;
AssertEquals (1, dt.Rows.Count); // not added yet
doc.DocumentElement.AppendChild (el);
AssertEquals (2, dt.Rows.Count); // added
row = doc.GetRowFromElement (el);
AssertEquals (DataRowState.Added, row.RowState); // changed
// Irrelevant element
XmlElement el2 = doc.CreateElement ("hoge");
row = doc.GetRowFromElement (el2);
AssertNull (row);
// created table 2 element (used later)
el = doc.CreateElement ("child");
row = doc.GetRowFromElement (el);
AssertEquals (DataRowState.Detached, row.RowState);
// Adding it to irrelevant element performs no row state change.
AssertEquals (1, dt2.Rows.Count); // not added yet
el2.AppendChild (el);
AssertEquals (1, dt2.Rows.Count); // still not added
row = doc.GetRowFromElement (el);
AssertEquals (DataRowState.Detached, row.RowState); // still detached here
}
示例6: GetRowFromElement
public void GetRowFromElement ()
{
XmlDataDocument doc = new XmlDataDocument ();
doc.DataSet.ReadXmlSchema ("Test/System.Xml/region.xsd");
doc.Load ("Test/System.Xml/region.xml");
XmlElement root = doc.DocumentElement;
DataRow row = doc.GetRowFromElement((XmlElement)root.FirstChild);
Assert.AreEqual ("1", row [0], "#E01");
row = doc.GetRowFromElement((XmlElement)root.ChildNodes [2]);
Assert.AreEqual ("3", row [0], "#E02");
}
示例7: getObjectTypeCommand
/// <summary>
/// Получение списка команд. Тестовый режим
/// </summary>
/// <param name="Name"></param>
/// <returns></returns>
public ArrayList getObjectTypeCommand(string TermType)
{
ArrayList arrFieldObj = new ArrayList();
SysObjectCommand spObject;
DataSet DS = new DataSet();
try
{
GetXMLFileData(DS, Config_Protocol);
}
catch (Exception e)
{
string sError = e.Message;
}
DataRow row;
XmlDataDocument XDoc = new XmlDataDocument(DS);
//XmlNodeList ProtocolNode = XDoc.DocumentElement.SelectNodes("//objtypes/objtype[@name='" + TermType + "']/cmd");
XmlNodeList ProtocolNode = XDoc.DocumentElement.SelectNodes("//objtypes/objtype[@name='" + TermType + "']");
XmlNode node;
foreach (XmlNode xmlNode in ProtocolNode)
{
row = XDoc.GetRowFromElement((XmlElement)xmlNode);
if (row != null)
{
spObject = new SysObjectCommand();
spObject.Value = xmlNode.Attributes.GetNamedItem("cmd").Value;
node = xmlNode.Attributes["index"];
if (node != null)
{
spObject.Index = Convert.ToInt16(xmlNode.Attributes.GetNamedItem("index").Value);
}
node = xmlNode.Attributes["mode"];
if (node != null)
{
spObject.Mode = xmlNode.Attributes.GetNamedItem("mode").Value;
}else{
spObject.Mode = "auto";
}
arrFieldObj.Add(spObject);
}
}
return arrFieldObj;
}
示例8: getObjectProtocol
/// <summary>
/// Возвращает массив элементов протокола
/// </summary>
/// <param name="TermType"></param>
public ArrayList getObjectProtocol(string TermType, int ProtocolIndex)
{
ArrayList arrField = new ArrayList();
//ArrayList arrMap;
//SysObjectProtocol sObject;
SysObjectProtocolMap pMap;
DataSet DS = new DataSet();
try
{
GetXMLFileData(DS, Config_Protocol);
}
catch (Exception e)
{
string sError = e.Message;
}
DataRow rowM;
XmlDataDocument XDoc = new XmlDataDocument(DS);
XmlNodeList ProtocolNode = XDoc.DocumentElement.SelectNodes("//objtypes/objtype[@name='" + TermType + "'][@index='" + ProtocolIndex + "']/col");
foreach (XmlNode xmlNode in ProtocolNode)
{
rowM = XDoc.GetRowFromElement((XmlElement)xmlNode);
if (rowM != null)
{
pMap.Name = rowM[0].ToString();
pMap.Index = Convert.ToInt16(rowM[1].ToString());
pMap.Pos = rowM[2].ToString();
pMap.Len = Convert.ToInt16(rowM[3].ToString());
if (rowM[4].ToString() == "")
{
rowM[4] = 0;
}
pMap.Comma = Convert.ToInt16(rowM[4].ToString());
pMap.Description = rowM[5].ToString();
pMap.Command = rowM[6].ToString();
//arrMap[pMap.Index] = pMap;
arrField.Add(pMap);
}
}
return arrField;
}