本文整理汇总了C#中System.Xml.XmlDocument.LoadXml方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlDocument.LoadXml方法的具体用法?C# System.Xml.XmlDocument.LoadXml怎么用?C# System.Xml.XmlDocument.LoadXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了System.Xml.XmlDocument.LoadXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnSave_Click
private void btnSave_Click(object sender, System.EventArgs e)
{
//Save the values to an XML file
//Could save to data source, Message Queue, etc.
System.Xml.XmlDocument aDOM = new System.Xml.XmlDocument();
System.Xml.XmlAttribute aAttribute;
aDOM.LoadXml("<AutomobileData/>");
//Add the First Name attribute to XML
aAttribute = aDOM.CreateAttribute("Manufacturer");
aAttribute.Value = txtManufact.Text;
aDOM.DocumentElement.Attributes.Append(aAttribute);
//Add the Last Name attribute to XML
aAttribute = aDOM.CreateAttribute("Model");
aAttribute.Value = txtModel.Text;
aDOM.DocumentElement.Attributes.Append(aAttribute);
//Add the DOB attribute to XML
aAttribute = aDOM.CreateAttribute("Year");
aAttribute.Value = txtYear.Text;
aDOM.DocumentElement.Attributes.Append(aAttribute);
//Add the SSN attribute to XML
aAttribute = aDOM.CreateAttribute("Color");
aAttribute.Value = txtColor.Text;
aDOM.DocumentElement.Attributes.Append(aAttribute);
//Save file to the file system
aDOM.Save("AutomobileData.xml");
}
示例2: DeserializeBannerTestSuccessfull
public void DeserializeBannerTestSuccessfull()
{
string content =
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Banners><Banner><id>605881</id><BannerPath>fanart/original/83462-18.jpg</BannerPath><BannerType>fanart</BannerType><BannerType2>1920x1080</BannerType2><Colors>|217,177,118|59,40,68|214,192,205|</Colors><Language>de</Language><Rating>9.6765</Rating><RatingCount>34</RatingCount><SeriesName>false</SeriesName><ThumbnailPath>_cache/fanart/original/83462-18.jpg</ThumbnailPath><VignettePath>fanart/vignette/83462-18.jpg</VignettePath></Banner></Banners>";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(content);
System.Xml.XmlNode bannersNode = doc.ChildNodes[1];
System.Xml.XmlNode bannerNode = bannersNode.ChildNodes[0];
Banner target = new Banner();
target.Deserialize(bannerNode);
Assert.Equal(605881, target.Id);
Assert.Equal("fanart/original/83462-18.jpg", target.BannerPath);
Assert.Equal(BannerTyp.fanart, target.Type);
Assert.Equal("1920x1080", target.Dimension);
Assert.Equal("|217,177,118|59,40,68|214,192,205|", target.Color);
Assert.Equal("de", target.Language);
Assert.Equal(9.6765, target.Rating);
Assert.Equal(34, target.RatingCount);
Assert.Equal(false, target.SeriesName);
Assert.Equal("_cache/fanart/original/83462-18.jpg", target.ThumbnailPath);
Assert.Equal("fanart/vignette/83462-18.jpg", target.VignettePath);
}
示例3: AdjustForDynamicLoad
/// <summary>
/// Adjusts for dynamic loading when no entry assembly is available/configurable.
/// </summary>
/// <remarks>
/// When dynamic loading is used, the configuration path from the
/// applications entry assembly to the connection setting might be broken.
/// This method makes up the necessary configuration entries.
/// </remarks>
public static void AdjustForDynamicLoad()
{
if (theObjectScopeProvider1 == null)
theObjectScopeProvider1 = new ObjectScopeProvider1();
if (theObjectScopeProvider1.myDatabase == null)
{
string assumedInitialConfiguration =
"<openaccess>" +
"<references>" +
"<reference assemblyname='PLACEHOLDER' configrequired='True'/>" +
"</references>" +
"</openaccess>";
System.Reflection.Assembly dll = theObjectScopeProvider1.GetType().Assembly;
assumedInitialConfiguration = assumedInitialConfiguration.Replace(
"PLACEHOLDER", dll.GetName().Name);
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(assumedInitialConfiguration);
Database db = Telerik.OpenAccess.Database.Get("DatabaseConnection1",
xmlDoc.DocumentElement,
new System.Reflection.Assembly[] { dll });
theObjectScopeProvider1.myDatabase = db;
}
}
示例4: toImgur
public static ImageInfo toImgur(Bitmap bmp)
{
ImageConverter convert = new ImageConverter();
byte[] toSend = (byte[])convert.ConvertTo(bmp, typeof(byte[]));
using (WebClient wc = new WebClient())
{
NameValueCollection nvc = new NameValueCollection
{
{ "image", Convert.ToBase64String(toSend) }
};
wc.Headers.Add("Authorization", Imgur.getAuth());
ImageInfo info = new ImageInfo();
try
{
byte[] response = wc.UploadValues("https://api.imgur.com/3/upload.xml", nvc);
string res = System.Text.Encoding.Default.GetString(response);
var xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(res);
info.link = new Uri(xmlDoc.SelectSingleNode("data/link").InnerText);
info.deletehash = xmlDoc.SelectSingleNode("data/deletehash").InnerText;
info.id = xmlDoc.SelectSingleNode("data/id").InnerText;
info.success = true;
}
catch (Exception e)
{
info.success = false;
info.ex = e;
}
return info;
}
}
示例5: GetShortUrl
public static string GetShortUrl(string longUrl)
{
string url = string.Format("http://api.bit.ly/shorten?format=xml&version=2.0.1&longUrl={0}&login={1}&apiKey={2}",
HttpUtility.UrlEncode(longUrl), login, apiKey);
try
{
System.Net.WebClient we = new System.Net.WebClient();
string ret = we.DownloadString(url);
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(ret);
System.Xml.XmlNode xnode = doc.DocumentElement.SelectSingleNode("results/nodeKeyVal/shortUrl");
if (!System.String.IsNullOrEmpty(xnode.InnerText))
{
return xnode.InnerText;
}
else
{
throw new Exception("Unable to shorten URL");
}
}
catch (Exception)
{
throw;
}
}
示例6: Update
public void Update()
{
if (!started)
{
return;
}
// Aceptamos conexiones entrantes
while (listener.Pending())
{
clients.Add(listener.AcceptTcpClient());
}
// Ahora leemos de los sockets
foreach (TcpClient c in clients)
{
if (c.Available > 0)
{
byte[] buffer = new byte[c.Available];
c.GetStream().Read(buffer, 0, c.Available);
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(System.Text.UTF8Encoding.GetEncoding(1250).GetString(buffer));
ServiceDispatcher.Instance.Dispatch(c, doc.FirstChild);
}
}
}
示例7: RazonSocial
public ActionResult RazonSocial(string rutempresa)
{
System.Xml.XmlDocument xDocumento = new System.Xml.XmlDocument();
servMEDAtencionProxy.servMEDAtencion obj = new servMEDAtencionProxy.servMEDAtencion();
var sRespuesta = obj.wsValidaEmpSiso(rutempresa);
if (sRespuesta != null)
{
xDocumento.LoadXml(sRespuesta);
XMLReader readXML = new XMLReader();
var data = readXML.ReturnListOfEmpresa(xDocumento);
if (data[0].GlsError != null)
{
string razonsocial = data[0].GlsError;
string[] razonsocial2 = razonsocial.Split(';');
if (razonsocial2.Count() > 1)
{
return Json(new { razonsocial = razonsocial2[1] });
}
else
{
return Json(new { razonsocial = razonsocial2[0] });
}
}
}
return Json(new { razonsocial = "No existe" });
}
示例8: RT1
public void RT1()
{
var doc = new XmlDocument();
doc.Begin("bookstore")
.Add("locations")
.Add("location", new { store_id = "1", address = "21 Jump St", phone = "123456"}).Up()
.Add("location", new { store_id = "2", address = "342 Pitt St", phone = "9876543"}).Up()
.Up()
.Add("books")
.Add("book", new {title = "The Enchiridion", price = "9.75"})
.Add("author", "Epictetus").Up()
.Add("stores_with_stock")
.Add("store", new { store_id = "1"}).Up()
.Up()
.Up()
.Add("book", new {title = "Signal to Noise", price = "5.82"})
.Add("author", "Neil Gaiman").Up()
.Add("author", "Dave McKean").Up()
.Add("stores_with_stock")
.Add("store", new { store_id = "1"}).Up()
.Add("store", new { store_id = "2"}).Up()
.Up()
.Up()
.Up()
.Add("staff")
.Add("member", new { firstname = "Ben", lastname = "Hughes", staff_id = "123"}).Up()
.Add("member", new { firstname = "Freddie", lastname = "Smith", staff_id = "124"}).Up();
Assert.AreEqual(Resource.BookstoreExpectedNotPretty, doc.ToString());
Assert.AreEqual(Resource.BookstoreExpectedPretty, doc.ToString(true));
var xmlDoc = new System.Xml.XmlDocument();
Assert.DoesNotThrow(() => xmlDoc.LoadXml(doc.ToString()));
}
示例9: deserialize
public static object deserialize(string json, Type type)
{
try
{
if (json.StartsWith("{") || json.StartsWith("["))
return JsonConvert.DeserializeObject(json, type);
else
{
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(json);
return JsonConvert.SerializeXmlNode(xmlDoc);
}
}
catch (IOException e)
{
throw new ApiException(500, e.Message);
}
catch (JsonSerializationException jse)
{
throw new ApiException(500, jse.Message);
}
catch (System.Xml.XmlException xmle)
{
throw new ApiException(500, xmle.Message);
}
}
示例10: read
public static Xml read(Connection connection)
{
System.Xml.XmlDocument document = new System.Xml.XmlDocument();
document.LoadXml(connection.stream.readString());
return new Xml(document);
}
示例11: Index
// GET: Encuesta
public ActionResult Index()
{
//XMLReader readXML = new XMLReader();
//var data = readXML.RetrunListOfEncuesta();
//Session["Resp"] = null;
Session["dictionary"] = null;
var dictionary = new Dictionary<string, string>();
Session["dictionary"] = dictionary;
Session["ENCUESTA_ID"] = null;
System.Xml.XmlDocument xDocumento = new System.Xml.XmlDocument();
List<Encuesta> data = new List<Encuesta>();
ServiceITLProxy.ServiceITL obj = new ServiceITLProxy.ServiceITL();
var sRespuesta = obj.Encuesta("");
if (sRespuesta != null)
{
xDocumento.LoadXml(sRespuesta);
XMLReader readXML = new XMLReader();
data = readXML.ReturnListOfEncuesta(xDocumento);
}
return View(data.ToList());
}
示例12: NewXmlDocument
/// <summary>
/// 新建
/// </summary>
/// <returns></returns>
public static System.Xml.XmlDocument NewXmlDocument()
{
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Root/>");
return xd;
}
示例13: btnSave_Click
private void btnSave_Click(object sender, System.EventArgs e)
{
//Save the values to an XML file
//Could save to data source, Message Queue, etc.
System.Xml.XmlDocument aDOM = new System.Xml.XmlDocument();
System.Xml.XmlAttribute aAttribute;
aDOM.LoadXml("<PersonnelData/>");
//Add the First Name attribute to XML
aAttribute = aDOM.CreateAttribute("FirstName");
aAttribute.Value = txtFName.Text;
aDOM.DocumentElement.Attributes.Append(aAttribute);
//Add the Last Name attribute to XML
aAttribute = aDOM.CreateAttribute("LastName");
aAttribute.Value = txtLName.Text;
aDOM.DocumentElement.Attributes.Append(aAttribute);
//Add the DOB attribute to XML
aAttribute = aDOM.CreateAttribute("DOB");
aAttribute.Value = txtDOB.Text;
aDOM.DocumentElement.Attributes.Append(aAttribute);
//Add the SSN attribute to XML
aAttribute = aDOM.CreateAttribute("SSN");
aAttribute.Value = txtSSN.Text;
aDOM.DocumentElement.Attributes.Append(aAttribute);
//Save file to the file system
aDOM.Save("PersonnelData.xml");
}
示例14: UpdateHierarchy
public bool UpdateHierarchy()
{
hierarchy = new Dictionary<string, OneNotePageInfo>();
string hierarchyXmlString = "";
bool success = instance.TryGetHierarchyAsXML(out hierarchyXmlString);
if (success)
{
System.Xml.XmlDocument hierarchyXml = new System.Xml.XmlDocument();
try
{
hierarchyXml.LoadXml(hierarchyXmlString);
}
catch (System.Exception exception)
{
etc.LoggerHelper.LogException(exception);
return false;
}
bool successPageInfos = TryGetOneNotePageInfos(hierarchyXml, out hierarchy);
if (successPageInfos)
{
int totalCount = hierarchy.Count;
int i = 0;
foreach (KeyValuePair<string, OneNotePageInfo> pageInfo in hierarchy)
{
i++;
string pageId = pageInfo.Key;
string pageInnerTextHash = "";
bool successHash = TryGetHashOfOneNotePage(pageId, out pageInnerTextHash);
if (successHash)
{
pageInfo.Value.HashOfInnerText = pageInnerTextHash;
pageInfo.Value.IsOkay = true;
FireProgressEvent(i, totalCount, pageInfo.Value.PageName);
}
else
{
etc.LoggerHelper.LogWarn("Unable to get a hash, pageId:{0}", pageId);
}
}
return true;
}
else
{
etc.LoggerHelper.LogWarn("Unable to parse the hierarchy");
return false;
}
}
else
{
etc.LoggerHelper.LogWarn("Unable to get a hierarchy");
return false;
}
}
示例15: Load
public static System.Xml.XmlDocument Load(string Xml)
{
var Doc = new System.Xml.XmlDocument();
Doc.LoadXml(Xml);
return Doc;
}