本文整理匯總了C#中System.Xml.XmlDataDocument.LoadXml方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDataDocument.LoadXml方法的具體用法?C# XmlDataDocument.LoadXml怎麽用?C# XmlDataDocument.LoadXml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlDataDocument
的用法示例。
在下文中一共展示了XmlDataDocument.LoadXml方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SimpleLoad
public void SimpleLoad ()
{
string xml001 = "<root/>";
XmlDataDocument doc = new XmlDataDocument ();
DataSet ds = new DataSet ();
ds.InferXmlSchema (new StringReader (xml001), null);
doc.LoadXml (xml001);
string xml002 = "<root><child/></root>";
doc = new XmlDataDocument ();
ds = new DataSet ();
ds.InferXmlSchema (new StringReader (xml002), null);
doc.LoadXml (xml002);
string xml003 = "<root><col1>test</col1><col1></col1></root>";
doc = new XmlDataDocument ();
ds = new DataSet ();
ds.InferXmlSchema (new StringReader (xml003), null);
doc.LoadXml (xml003);
string xml004 = "<set><tab1><col1>test</col1><col1>test2</col1></tab1><tab2><col2>test3</col2><col2>test4</col2></tab2></set>";
doc = new XmlDataDocument ();
ds = new DataSet ();
ds.InferXmlSchema (new StringReader (xml004), null);
doc.LoadXml (xml004);
}
示例2: TestMultipleLoadError
public void TestMultipleLoadError ()
{
DataSet ds = new DataSet ();
ds.ReadXml (new XmlTextReader (xml, XmlNodeType.Document, null));
// If there is already data element, Load() fails.
XmlDataDocument doc = new XmlDataDocument (ds);
doc.LoadXml (xml);
}
示例3: TestMultipleLoadNoError
public void TestMultipleLoadNoError ()
{
DataSet ds = new DataSet ();
DataTable dt = new DataTable ();
dt.Columns.Add ("col1");
ds.Tables.Add (dt);
XmlDataDocument doc = new XmlDataDocument (ds);
doc.LoadXml (xml);
}
示例4: TestMultipleLoadError
public void TestMultipleLoadError()
{
Assert.Throws<InvalidOperationException>(() =>
{
var ds = new DataSet();
ds.ReadXml(new XmlTextReader(_xml, XmlNodeType.Document, null));
// If there is already data element, Load() fails.
XmlDataDocument doc = new XmlDataDocument(ds);
doc.LoadXml(_xml);
});
}
示例5: buscaRetornoSCAN
/// <summary>
/// Busca Retorno do Web Service SCAN
/// </summary>
/// <returns></returns>
public string buscaRetornoSCAN(string UF_Empresa)
{
string sCabec = NfeCabecMsg();
string sDados = consultaNFe();
AssinaNFeXml bc = new AssinaNFeXml();
string xret = string.Empty;
try
{
if (_tpamb == 2)
{
HLP.WebService.v2_SCAN_Homologacao_NFeConsulta.NfeConsulta2 ws2 = new HLP.WebService.v2_SCAN_Homologacao_NFeConsulta.NfeConsulta2();
HLP.WebService.v2_SCAN_Homologacao_NFeConsulta.nfeCabecMsg cabec = new HLP.WebService.v2_SCAN_Homologacao_NFeConsulta.nfeCabecMsg();
cabec.versaoDados = _versaodados;
belUF objUf = new belUF();
cabec.cUF = objUf.RetornaCUF(UF_Empresa);
ws2.nfeCabecMsgValue = cabec;
ws2.ClientCertificates.Add(bc.BuscaNome(""));
XmlDataDocument xmlConsulta = new XmlDataDocument();
xmlConsulta.LoadXml(sDados);
XmlNode xNodeConsulta = xmlConsulta.DocumentElement;
xret = ws2.nfeConsultaNF2(xNodeConsulta).OuterXml;
}
else
{
HLP.WebService.v2_SCAN_Producao_NFeConsulta.NfeConsulta2 ws2 = new HLP.WebService.v2_SCAN_Producao_NFeConsulta.NfeConsulta2();
HLP.WebService.v2_SCAN_Producao_NFeConsulta.nfeCabecMsg cabec = new HLP.WebService.v2_SCAN_Producao_NFeConsulta.nfeCabecMsg();
cabec.versaoDados = _versaodados;
belUF objUf = new belUF();
cabec.cUF = objUf.RetornaCUF(UF_Empresa);
ws2.nfeCabecMsgValue = cabec;
ws2.ClientCertificates.Add(bc.BuscaNome(""));
XmlDataDocument xmlConsulta = new XmlDataDocument();
xmlConsulta.LoadXml(sDados);
XmlNode xNodeConsulta = xmlConsulta.DocumentElement;
xret = ws2.nfeConsultaNF2(xNodeConsulta).OuterXml;
}
return xret;
}
catch (Exception)
{
throw;
}
}
示例6: GetBankTransfers
public override List<BankTransfer> GetBankTransfers()
{
BankFileOperation = new SieradzFileOperation();
#pragma warning disable 618
XmlDocument xmlFile= new XmlDataDocument();
#pragma warning restore 618
List<BankTransfer> mBankTransferList = new List<BankTransfer>();
xmlFile.LoadXml(BankFileOperation.GetFileContent(SieradzBankFilesPathHolder.TransferFilesPath + @"mBankTransfers.xml"));
foreach (var childNode in xmlFile.DocumentElement.ChildNodes)
{
mBankTransferList.Add(GetTransferEntry(xmlFile.GetElementsByTagName((string) childNode.GetType().GetProperty("Name").GetValue(childNode)).Item(0).OuterXml));
}
return mBankTransferList;
}
示例7: rainfallImportXML
public rainfallImportXML(String StationsFile, String ReadingsFile, ref Dictionary<string, List<StationReading>> precip)
{
Stations = new XmlDataDocument();
Readings = new XmlDataDocument();
dStations = new Dictionary<string, Station>();
dReadings = new List<Reading>();
dStationReadings = new Dictionary<string, StationReading>();
StreamReader sr = new StreamReader(StationsFile);
String xmlStr = sr.ReadToEnd();
Stations.LoadXml(xmlStr);
sr = new StreamReader(ReadingsFile);
xmlStr = sr.ReadToEnd();
Readings.LoadXml(xmlStr);
XmlNodeList root = Stations.GetElementsByTagName("site");
foreach (XmlNode n in root)
{
dStations.Add(n.ChildNodes[1].InnerXml, new Station(n.ChildNodes[1].InnerXml, Double.Parse(n.ChildNodes[3].InnerXml), Double.Parse(n.ChildNodes[4].InnerXml), n.ChildNodes[2].InnerXml));
}
root = Readings.GetElementsByTagName("element");
foreach (XmlNode n in root)
{
dReadings.Add(new Reading(n.Attributes.GetNamedItem("station_id").Value, n.Attributes.GetNamedItem("date").Value, n.Attributes.GetNamedItem("precip_interval").Value, Double.Parse(n.Attributes.GetNamedItem("value").Value)));
}
Station curStation;
foreach (Reading r in dReadings)
{
if (precip.ContainsKey(r.DataTime))
{
curStation = dStations[r.StationID];
precip[r.DataTime].Add(new StationReading(curStation.Lat, curStation.Lon, r.Date, r.DataTime, r.Value));
}
else
{
List<StationReading> lsr = new List<StationReading>();
curStation = dStations[r.StationID];
lsr.Add(new StationReading(curStation.Lat, curStation.Lon, r.Date, r.DataTime, r.Value));
precip.Add(r.DataTime, lsr);
}
}
}
示例8: GetTransferEntry
protected override BankTransfer GetTransferEntry(string entry)
{
SieradzBankTransfer mBankTransfer = new SieradzBankTransfer();
#pragma warning disable 618
XmlDocument xmlNode = new XmlDataDocument();
#pragma warning restore 618
string datePattern = "d.m.yyyy";
DateTime currentDate = DateTime.Now;
var bankDictionary = SieradzBankTransfersUtils.Instance;
xmlNode.LoadXml(entry);
//TODO it's possible to reduce that sphagetti?
// IT FCKIN IS! @UCTT
mBankTransfer.TransferInfo.Amount = xmlNode.GetElementsByTagName("Amount").Item(0).InnerText;
mBankTransfer.TransferInfo.DestinationAccountNumber = xmlNode.GetElementsByTagName("DestinationAccountNumber").Item(0).InnerText;
mBankTransfer.TransferInfo.DestinationPersonName = xmlNode.GetElementsByTagName("DestinationPersonName").Item(0).InnerText;
mBankTransfer.TransferInfo.SourceAccountNumber = xmlNode.GetElementsByTagName("SourceAccountNumber").Item(0).InnerText;
mBankTransfer.TransferInfo.TransferDate = currentDate.ToString(datePattern);
mBankTransfer.TransferInfo.TransferTitle = xmlNode.GetElementsByTagName("TransferTitle").Item(0).InnerText;
mBankTransfer.SourceBank = bankDictionary.GetBankName(mBankTransfer.TransferInfo.SourceAccountNumber.Substring(2, 4));
mBankTransfer.DestinationBank = bankDictionary.GetBankName(mBankTransfer.TransferInfo.DestinationAccountNumber.Substring(2, 4));
return mBankTransfer;
}
示例9: NavigationSearchData
public NavigationSearchData(string xmltag)
{
Id = "";
FieldId = "";
Action = "";
SqlOperator = "";
SearchFrom = "";
SearchTo = "";
SqlType = "";
SearchField = "";
SqlField = "";
ControlType = "";
Static = "";
Dependency = "";
if (xmltag.Trim().StartsWith("<tag"))
{
var xdoc = new XmlDataDocument();
xdoc.LoadXml(xmltag);
var nodtag = xdoc.SelectSingleNode("tag");
if (nodtag != null)
{
if (nodtag.Attributes["search"] != null)
{
SearchField = nodtag.Attributes["search"].Value;
var s = SearchField.Split('/');
FieldId = s[s.Count() - 1];
ControlType = s[s.Count() - 2];
}
if (nodtag.Attributes["id"] != null) Id = nodtag.Attributes["id"].Value;
if (nodtag.Attributes["action"] != null) Action = nodtag.Attributes["action"].Value;
if (nodtag.Attributes["sqloperator"] != null) SqlOperator = nodtag.Attributes["sqloperator"].Value;
if (nodtag.Attributes["searchfrom"] != null) SearchFrom = nodtag.Attributes["searchfrom"].Value;
if (nodtag.Attributes["searchto"] != null) SearchTo = nodtag.Attributes["searchto"].Value;
if (nodtag.Attributes["sqltype"] != null) SqlType = nodtag.Attributes["sqltype"].Value;
if (nodtag.Attributes["sqlfield"] != null) SqlField = nodtag.Attributes["sqlfield"].Value;
if (nodtag.Attributes["static"] != null) Static = nodtag.Attributes["static"].Value;
if (nodtag.Attributes["dependency"] != null) Dependency = nodtag.Attributes["dependency"].Value;
}
}
}
示例10: CheckWebPartOrAppPartPresenceInSite
private bool CheckWebPartOrAppPartPresenceInSite(ClientContext clientContext, string targetWebPartXmlFileName, string targetWebPartXmlFilePath)
{
bool isWebPartInSite = false;
webParts targetWebPart = null;
string webPartPropertiesXml = string.Empty;
string webPartType = string.Empty;
clientContext.Load(clientContext.Web);
clientContext.ExecuteQuery();
ExceptionCsv.WebUrl = clientContext.Web.Url;
string exceptionCommentsInfo1 = string.Empty;
try
{
//Prepare Exception Comments
exceptionCommentsInfo1 = "Web Url: " + clientContext.Web.Url + ", Target Web Part File Name: " + targetWebPartXmlFileName + " , Target WebPart Xml File Path: " + targetWebPartXmlFilePath;
using (System.IO.FileStream fs = new System.IO.FileStream(targetWebPartXmlFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
System.IO.StreamReader reader = new System.IO.StreamReader(fs);
webPartPropertiesXml = reader.ReadToEnd();
}
Logger.AddMessageToTraceLogFile(Constants.Logging, "[CheckWebPartOrAppPartPresenceInSite] Checking for web part schema version");
Console.WriteLine("[CheckWebPartOrAppPartPresenceInSite] Checking for web part schema version");
if (webPartPropertiesXml.Contains("WebPart/v2"))
{
Logger.AddMessageToTraceLogFile(Constants.Logging, "[CheckWebPartOrAppPartPresenceInSite] Web part schema version is V2");
Console.WriteLine("[CheckWebPartOrAppPartPresenceInSite] Web part schema version is V2");
XmlDataDocument xmldoc = new XmlDataDocument();
xmldoc.LoadXml(webPartPropertiesXml);
webPartType = GetWebPartShortTypeName(xmldoc.DocumentElement.GetElementsByTagName("TypeName").Item(0).FirstChild.Value);
Logger.AddMessageToTraceLogFile(Constants.Logging, "[CheckWebPartOrAppPartPresenceInSite] Web part Type: " + webPartType);
Console.WriteLine("[CheckWebPartOrAppPartPresenceInSite] Web part Type: " + webPartType);
xmldoc = null;
}
else
{
Logger.AddMessageToTraceLogFile(Constants.Logging, "[CheckWebPartOrAppPartPresenceInSite] Web part schema version is V3");
Console.WriteLine("[CheckWebPartOrAppPartPresenceInSite] Web part schema version is V3");
using (System.IO.FileStream fs = new System.IO.FileStream(targetWebPartXmlFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
XmlReader reader = new XmlTextReader(fs);
XmlSerializer serializer = new XmlSerializer(typeof(webParts));
targetWebPart = (webParts)serializer.Deserialize(reader);
if (targetWebPart != null)
{
webPartType = GetWebPartShortTypeName(targetWebPart.webPart.metaData.type.name);
Logger.AddMessageToTraceLogFile(Constants.Logging, "[CheckWebPartOrAppPartPresenceInSite] Web part Type: " + webPartType);
Console.WriteLine("[CheckWebPartOrAppPartPresenceInSite] Web part Type: " + webPartType);
}
}
}
if (webPartType.Equals("ClientWebPart", StringComparison.CurrentCultureIgnoreCase))
{
foreach (var item in targetWebPart.webPart.data.properties)
{
if (item.name.Equals("FeatureId", StringComparison.CurrentCultureIgnoreCase))
{
Guid featureID = new Guid(item.Value);
isWebPartInSite = IsFeatureOnWeb(featureID,clientContext);
break;
}
}
}
else
{
Web web = clientContext.Site.RootWeb;
clientContext.Load(web, w => w.Url);
clientContext.ExecuteQuery();
List list = web.Lists.GetByTitle("Web Part Gallery");
CamlQuery camlQuery = CamlQuery.CreateAllItemsQuery(1000);
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(camlQuery);
clientContext.Load(items);
clientContext.ExecuteQuery();
foreach (ListItem item in items)
{
if (item["FileLeafRef"].ToString().Equals(targetWebPartXmlFileName, StringComparison.CurrentCultureIgnoreCase))
{
isWebPartInSite = true;
break;
}
}
}
}
//.........這裏部分代碼省略.........
示例11: GetWebPartUsage_DefaultPages
public void GetWebPartUsage_DefaultPages(string webPartType, ClientContext clientContext, string outPutDirectory)
{
ExceptionCsv.WebUrl = clientContext.Web.Url;
string exceptionCommentsInfo1 = string.Empty;
string webPartUsageFileName = outPutDirectory + "\\" + Constants.WEBPART_USAGE_ENTITY_FILENAME;
try
{
string webUrl = clientContext.Web.Url;
Logger.AddMessageToTraceLogFile(Constants.Logging, "[GetWebPartUsage_DefaultPages] Finding WebPartUsage details for Web Part: " + webPartType + " in Web: " + webUrl);
Console.WriteLine("[GetWebPartUsage_DefaultPages] Finding WebPartUsage details for Web Part: " + webPartType + " in Web: " + webUrl);
WebPartUsageEntity webPartUsageEntity = null;
List<WebPartUsageEntity> webPartUsage = new List<WebPartUsageEntity>();
if (clientContext != null)
{
clientContext.Load(clientContext.Web.RootFolder.Files);
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.File page in clientContext.Web.RootFolder.Files)
{
exceptionCommentsInfo1 = "Web Url: " + clientContext.Web.Url + ", Web Part Type: " + webPartType + ", PageTitle: " + page.ServerRelativeUrl;
if (Path.GetExtension(page.ServerRelativeUrl).Equals(".aspx", StringComparison.CurrentCultureIgnoreCase))
{
String pageUrl = page.ServerRelativeUrl;
Logger.AddMessageToTraceLogFile(Constants.Logging, "[GetWebPartUsage_DefaultPages] Checking for the Web Part on the Page: " + page.Name);
Console.WriteLine("[GetWebPartUsage_DefaultPages] Checking for the Web Part on the Page:" + page.Name);
// Requires Full Control permissions on the Web
LimitedWebPartManager webPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
clientContext.Load(webPartManager,
wpm => wpm.WebParts,
wpm => wpm.WebParts.Include(
wp => wp.WebPart.Hidden,
wp => wp.WebPart.IsClosed,
wp => wp.WebPart.Properties,
wp => wp.WebPart.Subtitle,
wp => wp.WebPart.Title,
wp => wp.WebPart.TitleUrl,
wp => wp.WebPart.ZoneIndex));
clientContext.ExecuteQuery();
foreach (WebPartDefinition webPartDefinition in webPartManager.WebParts)
{
Microsoft.SharePoint.Client.WebParts.WebPart webPart = webPartDefinition.WebPart;
string webPartPropertiesXml = GetWebPartPropertiesServiceCall(clientContext, webPartDefinition.Id.ToString(), pageUrl);
string WebPartTypeName = string.Empty;
if (webPartPropertiesXml.Contains("WebPart/v2"))
{
XmlDataDocument xmldoc = new XmlDataDocument();
xmldoc.LoadXml(webPartPropertiesXml);
WebPartTypeName = xmldoc.DocumentElement.GetElementsByTagName("TypeName").Item(0).FirstChild.Value;
xmldoc = null;
}
else
{
webParts webPartProp = null;
byte[] byteArray = Encoding.UTF8.GetBytes(webPartPropertiesXml);
using (MemoryStream stream = new MemoryStream(byteArray))
{
StreamReader streamReader = new StreamReader(stream);
System.Xml.XmlReader reader = new XmlTextReader(streamReader);
XmlSerializer serializer = new XmlSerializer(typeof(webParts));
webPartProp = (webParts)serializer.Deserialize(reader);
WebPartTypeName = webPartProp.webPart.metaData.type.name;
stream.Flush();
}
byteArray = null;
}
string actualWebPartType = GetWebPartShortTypeName(WebPartTypeName);
// only modify if we find the old web part
if (actualWebPartType.Equals(webPartType))
{
Logger.AddMessageToTraceLogFile(Constants.Logging, "[GetWebPartUsage_DefaultPages] Found WebPart: " + webPartType + " in Page: " + page.Name + ", " + page.ServerRelativeUrl);
Console.WriteLine("[GetWebPartUsage_DefaultPages] Found WebPart: " + webPartType + " in Page: " + page.Name + ", " + page.ServerRelativeUrl);
webPartUsageEntity = new WebPartUsageEntity();
webPartUsageEntity.PageUrl = pageUrl;
webPartUsageEntity.WebPartID = webPartDefinition.Id.ToString();
webPartUsageEntity.WebURL = webUrl;
webPartUsageEntity.WebPartTitle = webPart.Title;
webPartUsageEntity.ZoneIndex = webPart.ZoneIndex.ToString();
webPartUsageEntity.WebPartType = actualWebPartType;
FileUtility.WriteCsVintoFile(webPartUsageFileName, webPartUsageEntity, ref headerWebPart);
}
}
}
}
}
//.........這裏部分代碼省略.........
示例12: GetWebPartUsage
public void GetWebPartUsage(string webPartType, ClientContext clientContext,string outPutDirectory)
{
ExceptionCsv.WebUrl = clientContext.Web.Url;
string exceptionCommentsInfo1 = string.Empty;
string webPartUsageFileName = outPutDirectory + "\\" + Constants.WEBPART_USAGE_ENTITY_FILENAME;
try
{
//Initialized Exception and Logger.
WebPart_Initialization(outPutDirectory);
string webUrl = clientContext.Web.Url;
Logger.AddMessageToTraceLogFile(Constants.Logging, "############## Web Part Trasnformation Utility Execution Started ##############");
Console.WriteLine("############## Web Part Trasnformation Utility Execution Started ##############");
Logger.AddMessageToTraceLogFile(Constants.Logging, "[DATE TIME] " + Logger.CurrentDateTime());
Console.WriteLine("[DATE TIME] " + Logger.CurrentDateTime());
Logger.AddMessageToTraceLogFile(Constants.Logging, "[START][GetWebPartUsage]");
Console.WriteLine("[START][GetWebPartUsage]");
Logger.AddMessageToTraceLogFile(Constants.Logging, "[GetWebPartUsage] Initiated Logger and Exception Class. Logger and Exception file will be available at path: " + outPutDirectory);
Console.WriteLine("[GetWebPartUsage] Initiated Logger and Exception Class. Logger and Exception file will be available at path: " + outPutDirectory);
Logger.AddMessageToTraceLogFile(Constants.Logging, "[GetWebPartUsage] Finding WebPartUsage details for Web Part: " + webPartType + " in Web: " + webUrl);
Console.WriteLine("[GetWebPartUsage] Finding WebPartUsage details for Web Part: " + webPartType + " in Web: " + webUrl);
WebPartUsageEntity webPartUsageEntity = null;
List<WebPartUsageEntity> webPartUsage = new List<WebPartUsageEntity>();
//Prepare Exception Comments
exceptionCommentsInfo1 = "Web Url: " + clientContext.Web.Url + ", Web Part Type: " + webPartType;
if (clientContext != null)
{
List list = GetPageList(ref clientContext);
if (list != null)
{
var items = list.GetItems(CamlQuery.CreateAllItemsQuery());
//make sure to include the File on each Item fetched
clientContext.Load(items,
i => i.Include(
item => item.File,
item => item["EncodedAbsUrl"]));
clientContext.ExecuteQuery();
// Iterate through all available pages in the pages list
foreach (var item in items)
{
Microsoft.SharePoint.Client.File page = item.File;
String pageUrl = page.ServerRelativeUrl;// item.FieldValues["EncodedAbsUrl"].ToString();
Logger.AddMessageToTraceLogFile(Constants.Logging, "[GetWebPartUsage] Checking for the Web Part on the Page: " + page.Name);
Console.WriteLine("[GetWebPartUsage] Checking for the Web Part on the Page:" + page.Name);
// Requires Full Control permissions on the Web
LimitedWebPartManager webPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
clientContext.Load(webPartManager,
wpm => wpm.WebParts,
wpm => wpm.WebParts.Include(
wp => wp.WebPart.Hidden,
wp => wp.WebPart.IsClosed,
wp => wp.WebPart.Properties,
wp => wp.WebPart.Subtitle,
wp => wp.WebPart.Title,
wp => wp.WebPart.TitleUrl,
wp => wp.WebPart.ZoneIndex));
clientContext.ExecuteQuery();
foreach (WebPartDefinition webPartDefinition in webPartManager.WebParts)
{
Microsoft.SharePoint.Client.WebParts.WebPart webPart = webPartDefinition.WebPart;
string webPartPropertiesXml = GetWebPartPropertiesServiceCall(clientContext, webPartDefinition.Id.ToString(), pageUrl);
string WebPartTypeName = string.Empty;
if (webPartPropertiesXml.Contains("WebPart/v2"))
{
XmlDataDocument xmldoc = new XmlDataDocument();
xmldoc.LoadXml(webPartPropertiesXml);
WebPartTypeName = xmldoc.DocumentElement.GetElementsByTagName("TypeName").Item(0).FirstChild.Value;
xmldoc = null;
}
else
{
webParts webPartProp = null;
byte[] byteArray = Encoding.UTF8.GetBytes(webPartPropertiesXml);
using (MemoryStream stream = new MemoryStream(byteArray))
{
StreamReader streamReader = new StreamReader(stream);
System.Xml.XmlReader reader = new XmlTextReader(streamReader);
XmlSerializer serializer = new XmlSerializer(typeof(webParts));
webPartProp = (webParts)serializer.Deserialize(reader);
WebPartTypeName = webPartProp.webPart.metaData.type.name;
stream.Flush();
}
byteArray = null;
}
//.........這裏部分代碼省略.........
示例13: CreateFragmentBefore
public void CreateFragmentBefore(string xmlFragment, string xPathBefore)
{
XmlDataDocument newDoc = new XmlDataDocument();
newDoc.LoadXml(xmlFragment);
XmlNode newNode = _document.CreateDocumentFragment();
newNode.InnerXml = xmlFragment;
XmlNode beforeNode = _document.SelectSingleNode(xPathBefore);
if (_document.DocumentElement != null)
{
_document.DocumentElement.InsertBefore(newNode, beforeNode);
_document.Save(XmlFilePath);
}
}
示例14: listUsers
public System.Collections.ArrayList listUsers()
{
System.Collections.ArrayList list = new System.Collections.ArrayList();
string cmd = "listUsers";
ErrorCode = ERR_CODE_UNKNOWN_RESPONSE;
ErrorMsg = ERR_MSG_UNKNOWN_RESPONSE; //default error message
try
{
StringBuilder sbReq = new StringBuilder();
sbReq.Append(String.Format("{0}API?command={1}&session_id={2}", httpUri.AbsoluteUri, cmd, SessionId));
string resp = sendHTTPRequest(sbReq.ToString());
if (resp == null)
return null;
XmlDataDocument doc = new XmlDataDocument();
doc.LoadXml(resp);
XmlElement element = doc.DocumentElement;
if (element.Name == "CSL")
{
XmlNode node = doc.SelectSingleNode("CSL/Command");
if (node != null)
{
if (node.InnerXml.Equals("listUsers", StringComparison.OrdinalIgnoreCase))
{
node = doc.SelectSingleNode("CSL/Account");
if (node != null)
{
while (node != null)
{
USER_INFO info = new USER_INFO();
XmlAttributeCollection atts = node.Attributes;
info.username = atts.GetNamedItem("username").Value;
//info.password = atts.GetNamedItem("password").Value;
info.desc = atts.GetNamedItem("desc").Value;
info.level = int.Parse(atts.GetNamedItem("level").Value);
list.Add(info);
node = node.NextSibling;
}
ErrorCode = ERR_CODE_NO_ERROR;
ErrorMsg = "";
return list;
}
node = doc.SelectSingleNode("CSL/Error");
if (node != null)
{
//<Error>
foreach (XmlAttribute att in node.Attributes)
{
if (att.Name.Equals("msg", StringComparison.OrdinalIgnoreCase))
{
ErrorMsg = att.InnerXml.Substring(6).Trim();
}
else if (att.Name.Equals("code", StringComparison.OrdinalIgnoreCase))
{
Int32.TryParse(att.InnerXml, out ErrorCode);
}
}
return null;
}
}
}
}
}
catch (WebException wex)
{
ErrorMsg = wex.Message;
return null;
}
ErrorMsg = ERR_MSG_UNKNOWN_RESPONSE;
return null;
}
示例15: 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
}