本文整理汇总了C#中System.Xml.XmlDocument.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.Normalize方法的具体用法?C# XmlDocument.Normalize怎么用?C# XmlDocument.Normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MostrarDestinoIco
public ActionResult MostrarDestinoIco(String url)
{
if (ValidateUrl(url))
{
String xml = WebRequest(oAuthTwitter.Method.GET, url, String.Empty);
if (xml != "")
{
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.LoadXml(xml);
myXmlDocument.Normalize();
XmlNodeList myNodeList = myXmlDocument.GetElementsByTagName("CUENTA");
IList<Destino> destinos = new List<Destino>();
var destino = new Destino();
foreach (XmlNode nodo in myNodeList)
{
destino.Direccion = nodo.ChildNodes[6].InnerText;
destino.Descripcion = nodo.ChildNodes[2].InnerText;
destino.Fecha = DateTime.Parse(nodo.ChildNodes[8].InnerText);
destino.Url = nodo.ChildNodes[4].InnerText;
destinos.Add(destino);
}
return View(destinos);
}
}
return View();
}
示例2: FormatHtml
/// <summary>
/// Formats XHTML as an XML document with perfect indentation.
/// </summary>
/// <param name="html">The XHTML to format.</param>
/// <returns>The formatted XHTML.</returns>
public static string FormatHtml(string html)
{
// Create a memory stream to store the formatted output
using (MemoryStream memoryStream = new MemoryStream())
{
try
{
// Get the HTML output from the HTTP response stream and load it into an XML document
XmlDocument document = new XmlDocument();
document.PreserveWhitespace = false;
document.LoadXml(html);
document.Normalize();
// Write the document to the memory stream
XmlTextWriter writer = new XmlTextWriter(memoryStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 2;
document.Save(writer);
// Return the formatted XHTML
return Encoding.UTF8.GetString(memoryStream.ToArray());
}
catch (XmlException)
{
return null;
}
}
}
示例3: Canonicalize
public static string Canonicalize(string xml)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
doc.Normalize();
return doc.DocumentElement.OuterXml;
}
示例4: LoadBots
public void LoadBots()
{
if (!File.Exists(BotSaveFile))
{
return;
}
try
{
Cover.SetVisible(true);
XmlDocument LoadFile = new XmlDocument();
LoadFile.Load(BotSaveFile);
LoadFile.Normalize();
Cover.ExecuteOnBar((BarExecutable)((ProgressBar Bar) =>
{
Bar.Minimum = 0;
Bar.Maximum = LoadFile.SelectNodes("//Version").Count;
Bar.Value = 0;
}));
XmlNodeList Owners = LoadFile.SelectSingleNode("/SavedBots").SelectNodes("Owner");
for (int x = 0; x < Owners.Count; x++)
{
string OwnerName = Owners[x].Attributes["Name"].Value;
XmlNodeList Bots = Owners[x].SelectNodes("Bot");
for (int y = 0; y < Bots.Count; y++)
{
string BotName = Bots[x].Attributes["Name"].Value;
XmlNodeList Versions = Bots[y].SelectNodes("Version");
for (int z = 0; z < Versions.Count; z++)
{
string Version = Versions[z].Attributes["Value"].Value;
string BotPath = Versions[z].InnerText;
VersionTreeViewItem Temp;
this.Bots.AddVersion(OwnerName, BotName, Version, BotPath, out Temp);
Cover.ExecuteOnBar((BarExecutable)((ProgressBar Bar) =>
{
Bar.Value++;
}));
}
}
}
}
catch
{
throw new Exception("Failed to load all bots.");
}
finally
{
Cover.SetVisible(false);
}
}
示例5: loadFiles
// ------------------------------------------------------------------
#endregion
#region Private methods.
// ------------------------------------------------------------------
/// <summary>
/// Load files from FileSystem
/// </summary>
private void loadFiles()
{
_resxFiles = new List<ResxFile>();
foreach (var item in _gridEditableData.GetFileInformationsSorted())
{
using (var reader = XmlReader.Create(item.File.FullName))
{
var doc = new XmlDocument();
doc.Load(reader);
doc.Normalize();
_resxFiles.Add(
new ResxFile
{
FileInformation = item,
FilePath = item.File,
Document = doc
});
}
}
}
示例6: AreIdentical
/// <summary>
/// Compares two <code>XmlDocument</code>s.
/// Returns TRUE if the xml dcouments have the same nodes, in the same position with the exact attributes.
/// </summary>
/// <returns>True if the xml dcouments have the same nodes, in the same position with the exact attributes.</returns>
public static bool AreIdentical(XmlDocument xmlDoc1, XmlDocument xmlDoc2)
{
//normalize the documents to avoid adjacent XmlText nodes.
xmlDoc1.Normalize();
xmlDoc2.Normalize();
XmlNodeList nodeList1 = xmlDoc1.ChildNodes;
XmlNodeList nodeList2 = xmlDoc2.ChildNodes;
bool same = true;
if (nodeList1.Count != nodeList2.Count)
{
return false;
}
IEnumerator enumerator1 = nodeList1.GetEnumerator();
IEnumerator enumerator2 = nodeList2.GetEnumerator();
while (enumerator1.MoveNext() && enumerator2.MoveNext() && same)
{
same = CompareNodes((XmlNode)enumerator1.Current, (XmlNode)enumerator2.Current);
}
return same;
}
示例7: WriteableContactProperties
public WriteableContactProperties(Stream source, bool ownsStream)
{
// _disposed = false;
// _modified = false;
Assert.IsNotNull(source);
try
{
_document = new XmlDocument();
_document.Schemas.Add(_ContactSchemaCache);
source.Position = 0;
_document.Load(source);
if (ownsStream)
{
Utility.SafeDispose(ref source);
}
// Coalesce adjacent Text nodes. The XSD may make this superfluous.
_document.Normalize();
_ValidateDom();
_contactTree = new ContactTree(_document);
_namespaceManager = new XmlElementManager(_document);
}
catch (XmlException xmlEx)
{
throw new InvalidDataException("Invalid XML", xmlEx);
}
}
示例8: createXMLDocFromPackage
/// <summary>
/// Creates/serializes an XML doc from the persisted DTS package object.
/// </summary>
/// <returns>The XML doc.</returns>
private XmlDocument createXMLDocFromPackage()
{
XmlDocument xDoc = new XmlDocument();
XmlNode xRoot = xDoc.CreateNode(XmlNodeType.Element, "DTS_File", "");
XmlAttribute xAttr;
xAttr = xDoc.CreateAttribute("Package_Name", "");
xAttr.Value = oPackage.Name;
xRoot.Attributes.Append(xAttr);
// create top level Package_Property nodes
int zz = 0;
CreateChildNodes(xDoc, ref xRoot, typeof(DTS.Package2Class), "Package", oPackage);
// create GlobalVariables nodes
XmlNode xGlobalVariables = xDoc.CreateNode(XmlNodeType.Element, "GlobalVariables", "");
zz = 0;
foreach( DTS.GlobalVariable2 gv2 in oPackage.GlobalVariables )
{
Type t = typeof(DTS.GlobalVariable2);
string nodeName = "GlobalVariable_" + zz.ToString();
CreateChildNodes(xDoc, ref xGlobalVariables, t, nodeName, gv2);
zz ++;
}
xRoot.SelectSingleNode("descendant::Package").RemoveChild(xRoot.SelectSingleNode("descendant::Package/GlobalVariables"));
xRoot.SelectSingleNode("descendant::Package").AppendChild(xGlobalVariables);
// create connections nodes
XmlNode xConnections = xDoc.CreateNode(XmlNodeType.Element, "Connections", "");
zz = 0;
foreach( DTS.Connection2 cn in oPackage.Connections )
{
Type t = typeof(DTS.Connection2);
string nodeName = "Connection_" + zz.ToString();
CreateChildNodes(xDoc, ref xConnections, t, nodeName, cn);
zz ++;
}
xRoot.SelectSingleNode("descendant::Package").RemoveChild(xRoot.SelectSingleNode("descendant::Package/Connections"));
xRoot.SelectSingleNode("descendant::Package").AppendChild(xConnections);
// create steps nodes
XmlNode xSteps = xDoc.CreateNode(XmlNodeType.Element, "Steps", "");
zz = 0;
foreach( DTS.Step2 sp in oPackage.Steps )
{
Type t = typeof(DTS.Step2);
string nodeName = "Step_" + zz.ToString();
CreateChildNodes(xDoc, ref xSteps, t, nodeName, sp);
zz ++;
}
xRoot.SelectSingleNode("descendant::Package").RemoveChild(xRoot.SelectSingleNode("descendant::Package/Steps"));
xRoot.SelectSingleNode("descendant::Package").AppendChild(xSteps);
// create tasks nodes
XmlNode xTasks = xDoc.CreateNode(XmlNodeType.Element, "Tasks", "");
zz = 0;
foreach( DTS.Task ts in oPackage.Tasks )
{
Type t = typeof(DTS.Task);
string nodeName = "Task_" + zz.ToString();
CreateChildNodes(xDoc, ref xTasks, t, nodeName, ts);
// remove customtask node as it is only being used to get the customtask properties under the customtaskID node
xTasks.SelectSingleNode("child::" + nodeName).RemoveChild(xTasks.SelectSingleNode("child::" + nodeName + "/CustomTask"));
zz ++;
}
xRoot.SelectSingleNode("descendant::Package").RemoveChild(xRoot.SelectSingleNode("descendant::Package/Tasks"));
xRoot.SelectSingleNode("descendant::Package").AppendChild(xTasks);
xDoc.AppendChild(xRoot);
xDoc.Normalize();
return xDoc;
}
示例9: ToXml
public static XmlNode ToXml(IEnumerable<itemHistory> itemsHistorial)
{
XmlDocument xmlDoc = new XmlDocument();
string nodo = "<Historial>";
if(itemsHistorial!=null)
foreach (itemHistory item in itemsHistorial)
nodo += item.ToNodoXml().OuterXml;
nodo += "</Historial>";
xmlDoc.LoadXml(nodo);
xmlDoc.Normalize();
return xmlDoc.FirstChild;
}
示例10: ToNodoXml
public XmlNode ToNodoXml()
{
XmlDocument xmlDoc = new XmlDocument();
string nodos = itemHistory.ToXml(historial).OuterXml;
string nodoItemCronos = "<ItemCronos>";
if (!String.IsNullOrEmpty(Descripcion))
nodoItemCronos += "<DescripcionItem>" + Descripcion.EscaparCaracteresXML() + "</DescripcionItem>";
else nodoItemCronos += "<DescripcionItem/>";
nodoItemCronos += nodos + "</ItemCronos>";
xmlDoc.LoadXml(nodoItemCronos);
xmlDoc.Normalize();
return xmlDoc.FirstChild;
}
示例11: parseXmlString
// Helper method that outputs a DOM element from a XML string.
private static XmlElement parseXmlString(String xmlString)
{
var document = new XmlDocument();
document.LoadXml(xmlString);
document.Normalize();
return document.DocumentElement;
}
示例12: MarshallRelationshipPart
/**
* Save relationships into the part.
*
* @param rels
* The relationships collection to marshall.
* @param relPartName
* Part name of the relationship part to marshall.
* @param zos
* Zip output stream in which to save the XML content of the
* relationships serialization.
*/
public static bool MarshallRelationshipPart(
PackageRelationshipCollection rels, PackagePartName relPartName,
ZipOutputStream zos)
{
// Building xml
XmlDocument xmlOutDoc = new XmlDocument();
// make something like <Relationships
// xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(xmlOutDoc.NameTable);
xmlnsManager.AddNamespace("x", PackageNamespaces.RELATIONSHIPS);
XmlNode root = xmlOutDoc.AppendChild(xmlOutDoc.CreateElement(PackageRelationship.RELATIONSHIPS_TAG_NAME, PackageNamespaces.RELATIONSHIPS));
// <Relationship
// TargetMode="External"
// Id="rIdx"
// Target="http://www.custom.com/images/pic1.jpg"
// Type="http://www.custom.com/external-resource"/>
Uri sourcePartURI = PackagingUriHelper
.GetSourcePartUriFromRelationshipPartUri(relPartName.URI);
foreach (PackageRelationship rel in rels)
{
// the relationship element
XmlElement relElem = xmlOutDoc.CreateElement(PackageRelationship.RELATIONSHIP_TAG_NAME,PackageNamespaces.RELATIONSHIPS);
// the relationship ID
relElem.SetAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel.Id);
// the relationship Type
relElem.SetAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel
.RelationshipType);
// the relationship Target
String targetValue;
Uri uri = rel.TargetUri;
if (rel.TargetMode == TargetMode.External)
{
// Save the target as-is - we don't need to validate it,
// alter it etc
targetValue = uri.OriginalString;
// add TargetMode attribute (as it is external link external)
relElem.SetAttribute(
PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME,
"External");
}
else
{
targetValue = PackagingUriHelper.RelativizeUri(
sourcePartURI, rel.TargetUri, true).ToString();
}
relElem.SetAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME,
targetValue);
xmlOutDoc.DocumentElement.AppendChild(relElem);
}
xmlOutDoc.Normalize();
// String schemaFilename = Configuration.getPathForXmlSchema()+
// File.separator + "opc-relationships.xsd";
// Save part in zip
ZipEntry ctEntry = new ZipEntry(ZipHelper.GetZipURIFromOPCName(
relPartName.URI.ToString()).OriginalString);
try
{
zos.PutNextEntry(ctEntry);
StreamHelper.SaveXmlInStream(xmlOutDoc, zos);
zos.CloseEntry();
}
catch (IOException e)
{
logger.Log(POILogger.ERROR,"Cannot create zip entry " + relPartName, e);
return false;
}
return true; // success
}
示例13: Collect
public int Collect()
{
Queue<Uri> uriQueue = new Queue<Uri>(this.subscriptionList);
Queue<Task<IEnumerable<Entry>>> taskQueue = new Queue<Task<IEnumerable<Entry>>>();
List<Entry> entryList = new List<Entry>();
int successfulRow = 0;
this.entryList.Clear();
while (uriQueue.Count > 0 || taskQueue.Count > 0)
{
while (uriQueue.Count > 0 && taskQueue.Count < 2 * Environment.ProcessorCount)
{
WebRequest webRequest = WebRequest.Create(uriQueue.Dequeue());
Task<IEnumerable<Entry>> task = new Task<IEnumerable<Entry>>(delegate (object state)
{
WebRequest request = (WebRequest)state;
WebResponse response = null;
Stream s = null;
BufferedStream bs = null;
try
{
response = request.GetResponse();
s = response.GetResponseStream();
bs = new BufferedStream(s);
s = null;
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(bs);
xmlDocument.Normalize();
if (xmlDocument.DocumentElement.NamespaceURI.Equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#") && xmlDocument.DocumentElement.LocalName.Equals("RDF"))
{
return ParseRss10(xmlDocument.DocumentElement);
}
else if (xmlDocument.DocumentElement.Name.Equals("rss"))
{
foreach (XmlAttribute xmlAttribute in xmlDocument.DocumentElement.Attributes)
{
if (xmlAttribute.Name.Equals("version"))
{
if (xmlAttribute.Value.Equals("2.0"))
{
return ParseRss20(xmlDocument.DocumentElement);
}
break;
}
}
}
else if (xmlDocument.DocumentElement.NamespaceURI.Equals("http://www.w3.org/2005/Atom") && xmlDocument.DocumentElement.LocalName.Equals("feed"))
{
return ParseAtom10(xmlDocument.DocumentElement);
}
}
finally
{
if (bs != null)
{
bs.Close();
}
if (s != null)
{
s.Close();
}
if (response != null)
{
response.Close();
}
}
return Enumerable.Empty<Entry>();
}, webRequest, TaskCreationOptions.LongRunning);
if (this.timeout.HasValue)
{
webRequest.Timeout = this.timeout.Value;
}
if (this.userAgent != null)
{
HttpWebRequest httpWebRequest = webRequest as HttpWebRequest;
if (httpWebRequest != null)
{
httpWebRequest.UserAgent = this.userAgent;
}
}
taskQueue.Enqueue(task);
task.Start();
}
Task<IEnumerable<Entry>>[] tasks = taskQueue.ToArray();
int index = Task<IEnumerable<Entry>>.WaitAny(tasks);
//.........这里部分代码省略.........
示例14: saveToolStripButton_Click
private void saveToolStripButton_Click(object sender, EventArgs e)
{
if (imageset_filename.Length == 0)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Imageset Files|*.imageset";
if (DialogResult.OK == sfd.ShowDialog(this))
{
imageset_filename = sfd.FileName;
}
else
return;
}
layout_editor.ClearUndoRedo();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
XmlElement imageset_el = doc.CreateElement("Imageset");
imageset_el.SetAttribute("Name", imageset_name);
imageset_el.SetAttribute("Imagefile", imagefile);
imageset_el.SetAttribute("NativeHorzRes", NativeHorzRes.ToString());
imageset_el.SetAttribute("NativeVertRes", NativeVertRes.ToString());
imageset_el.SetAttribute("AutoScaled", AutoScaled.ToString());
doc.AppendChild(imageset_el);
foreach (TextureRegion reg in layout_editor.Regions)
{
XmlElement el = doc.CreateElement("Image");
el.SetAttribute("Name", reg.Name);
el.SetAttribute("XPos", reg.Rectangle.X.ToString());
el.SetAttribute("YPos", reg.Rectangle.Y.ToString());
el.SetAttribute("Width", reg.Rectangle.Width.ToString());
el.SetAttribute("Height", reg.Rectangle.Height.ToString());
imageset_el.AppendChild(el);
}
doc.Normalize();
doc.Save(imageset_filename);
}
示例15: MostrarViaje
public ActionResult MostrarViaje(String url)
{
if (ValidateUrl(url))
{
String xml = WebRequest(oAuthTwitter.Method.GET, url, String.Empty);
if (xml != "")
{
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.LoadXml(xml);
myXmlDocument.Normalize();
XmlNodeList myNodeList = myXmlDocument.GetElementsByTagName("ViajeXml");
IList<Viaje> viajes = new List<Viaje>();
IList<Destino> destinos = new List<Destino>();
Viaje viaje=null;
foreach (XmlNode nodo in myNodeList)
{
viaje = new Viaje();
viaje.Destino = nodo.ChildNodes[0].InnerText;
viaje.Nombre = nodo.ChildNodes[5].InnerText;
viaje.FechaFin = DateTime.Parse(nodo.ChildNodes[1].InnerText);
viaje.FechaInicio = DateTime.Parse(nodo.ChildNodes[2].InnerText);
viaje.Hospedaje = nodo.ChildNodes[3].InnerText;
viaje.IdViaje = Int32.Parse(nodo.ChildNodes[4].InnerText);
viaje.Privacidad = nodo.ChildNodes[6].InnerText;
XmlNodeList myNodeList2 = nodo.ChildNodes[7].ChildNodes;
foreach (XmlNode nodo2 in myNodeList2)
{
Destino destino = new Destino();
destino.Descripcion =nodo2.ChildNodes[0].InnerText;
destino.Direccion = nodo2.ChildNodes[1].InnerText;
destino.Fecha = DateTime.Parse(nodo2.ChildNodes[2].InnerText);
destinos.Add(destino);
}
viaje.Destinos = destinos;
}
return View(viaje);
}
}
return View();
}