本文整理汇总了C#中System.Xml.XmlDocument.ToIndentedString方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.ToIndentedString方法的具体用法?C# XmlDocument.ToIndentedString怎么用?C# XmlDocument.ToIndentedString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.ToIndentedString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveToDisk
/// <summary>
/// Saves Modules to disk
/// </summary>
private static void SaveToDisk(nHydrateModel modelRoot, IEnumerable<Module> list, string rootFolder, nHydrateDiagram diagram, List<string> generatedFileList)
{
var folder = rootFolder;
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
var document = new XmlDocument();
document.LoadXml(@"<configuration type=""module""></configuration>");
foreach (var item in list)
{
var moduleNode = XmlHelper.AddElement(document.DocumentElement, "module") as XmlElement;
XmlHelper.AddLineBreak(moduleNode);
XmlHelper.AddCData(moduleNode, "summary", item.Summary);
XmlHelper.AddAttribute(moduleNode, "id", item.Id);
XmlHelper.AddAttribute(moduleNode, "name", item.Name);
XmlHelper.AddLineBreak(moduleNode);
var rulesNodes = XmlHelper.AddElement(moduleNode, "ruleset") as XmlElement;
XmlHelper.AddLineBreak((XmlElement)rulesNodes);
foreach (var rule in item.ModuleRules.OrderBy(x => x.Name))
{
var fieldNode = XmlHelper.AddElement(rulesNodes, "rule");
XmlHelper.AddLineBreak((XmlElement)fieldNode);
XmlHelper.AddCData((XmlElement)fieldNode, "summary", rule.Summary);
XmlHelper.AddLineBreak((XmlElement)fieldNode);
XmlHelper.AddAttribute(fieldNode, "status", rule.Status.ToString("d"));
XmlHelper.AddAttribute(fieldNode, "dependentmodule", rule.DependentModule);
XmlHelper.AddAttribute(fieldNode, "name", rule.Name);
XmlHelper.AddAttribute(fieldNode, "inclusion", rule.Inclusion);
XmlHelper.AddAttribute(fieldNode, "enforced", rule.Enforced);
XmlHelper.AddLineBreak((XmlElement)rulesNodes);
}
}
var f = Path.Combine(folder, "modules.configuration.xml");
WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
WriteReadMeFile(folder, generatedFileList);
}
示例2: SaveRelations
private static void SaveRelations(string folder, Entity item, List<string> generatedFileList)
{
var document = new XmlDocument();
document.LoadXml(@"<configuration type=""entity.relations"" id=""" + item.Id + @"""></configuration>");
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
foreach (var relation in item.RelationshipList)
{
var relationNode = XmlHelper.AddElement(document.DocumentElement, "relation");
XmlHelper.AddLineBreak((XmlElement)relationNode);
XmlHelper.AddCData((XmlElement)relationNode, "summary", relation.Summary);
XmlHelper.AddLineBreak((XmlElement)relationNode);
XmlHelper.AddAttribute(relationNode, "id", relation.InternalId);
XmlHelper.AddAttribute(relationNode, "childid", relation.ChildEntity.Id);
XmlHelper.AddAttribute(relationNode, "isenforced", relation.IsEnforced);
XmlHelper.AddAttribute(relationNode, "isinherited", false);
XmlHelper.AddAttribute(relationNode, "rolename", relation.RoleName);
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
//Process the columns
var relationColumnsNodes = XmlHelper.AddElement((XmlElement)relationNode, "relationfieldset") as XmlElement;
XmlHelper.AddLineBreak((XmlElement)relationColumnsNodes);
foreach (var relationField in relation.FieldMapList())
{
var realtionFieldNode = XmlHelper.AddElement(relationColumnsNodes, "field");
XmlHelper.AddAttribute(realtionFieldNode, "id", relationField.Id);
XmlHelper.AddAttribute(realtionFieldNode, "sourcefieldid", relationField.SourceFieldId);
XmlHelper.AddAttribute(realtionFieldNode, "targetfieldid", relationField.TargetFieldId);
XmlHelper.AddLineBreak((XmlElement)relationColumnsNodes);
}
}
foreach (var relation in item.ParentRelationshipList)
{
var relationNode = XmlHelper.AddElement(document.DocumentElement, "relation");
XmlHelper.AddLineBreak((XmlElement)relationNode);
XmlHelper.AddCData((XmlElement)relationNode, "summary", relation.Summary);
XmlHelper.AddLineBreak((XmlElement)relationNode);
XmlHelper.AddAttribute(relationNode, "id", relation.InternalId);
XmlHelper.AddAttribute(relationNode, "parentid", relation.ParentInheritedEntity.Id);
XmlHelper.AddAttribute(relationNode, "isenforced", relation.IsEnforced);
XmlHelper.AddAttribute(relationNode, "isinherited", true);
XmlHelper.AddAttribute(relationNode, "rolename", relation.RoleName);
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
}
foreach (var relation in item.RelationshipViewList)
{
var relationNode = XmlHelper.AddElement(document.DocumentElement, "relation");
XmlHelper.AddAttribute(relationNode, "isviewrelation", "true");
XmlHelper.AddLineBreak((XmlElement)relationNode);
XmlHelper.AddCData((XmlElement)relationNode, "summary", relation.Summary);
XmlHelper.AddLineBreak((XmlElement)relationNode);
XmlHelper.AddAttribute(relationNode, "id", relation.InternalId);
XmlHelper.AddAttribute(relationNode, "childid", relation.ChildView.Id);
XmlHelper.AddAttribute(relationNode, "rolename", relation.RoleName);
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
//Process the columns
var relationColumnsNodes = XmlHelper.AddElement((XmlElement)relationNode, "relationfieldset") as XmlElement;
XmlHelper.AddLineBreak((XmlElement)relationColumnsNodes);
foreach (var relationField in relation.FieldMapList())
{
var realtionFieldNode = XmlHelper.AddElement(relationColumnsNodes, "field");
XmlHelper.AddAttribute(realtionFieldNode, "id", relationField.Id);
XmlHelper.AddAttribute(realtionFieldNode, "sourcefieldid", relationField.SourceFieldId);
XmlHelper.AddAttribute(realtionFieldNode, "targetfieldid", relationField.TargetFieldId);
XmlHelper.AddLineBreak((XmlElement)relationColumnsNodes);
}
}
var f = Path.Combine(folder, item.Name + ".relations.xml");
WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
}
示例3: SaveDiagramFiles
private static void SaveDiagramFiles(string rootFolder, nHydrateDiagram diagram, List<string> generatedFileList)
{
var fileName = Path.Combine(rootFolder, "diagram.xml");
var document = new XmlDocument();
document.LoadXml(@"<configuration type=""diagram""></configuration>");
foreach (var shape in diagram.NestedChildShapes)
{
if (shape is EntityShape)
{
var item = ((shape as EntityShape).ModelElement as Entity);
var node = XmlHelper.AddElement(document.DocumentElement, "element");
XmlHelper.AddAttribute(node, "id", shape.ModelElement.Id);
XmlHelper.AddAttribute(node, "bounds", shape.AbsoluteBoundingBox.ToXmlValue());
}
else if (shape is ViewShape)
{
var item = ((shape as ViewShape).ModelElement as View);
var node = XmlHelper.AddElement(document.DocumentElement, "element");
XmlHelper.AddAttribute(node, "id", shape.ModelElement.Id);
XmlHelper.AddAttribute(node, "bounds", shape.AbsoluteBoundingBox.ToXmlValue());
}
else if (shape is StoredProcedureShape)
{
var item = ((shape as StoredProcedureShape).ModelElement as StoredProcedure);
var node = XmlHelper.AddElement(document.DocumentElement, "element");
XmlHelper.AddAttribute(node, "id", shape.ModelElement.Id);
XmlHelper.AddAttribute(node, "bounds", shape.AbsoluteBoundingBox.ToXmlValue());
}
else if (shape is FunctionShape)
{
var item = ((shape as FunctionShape).ModelElement as Function);
var node = XmlHelper.AddElement(document.DocumentElement, "element");
XmlHelper.AddAttribute(node, "id", shape.ModelElement.Id);
XmlHelper.AddAttribute(node, "bounds", shape.AbsoluteBoundingBox.ToXmlValue());
}
}
WriteFileIfNeedBe(fileName, document.ToIndentedString(), generatedFileList);
}
示例4: SaveEntityMetaData
private static void SaveEntityMetaData(string folder, Entity item, List<string> generatedFileList)
{
var f = Path.Combine(folder, item.Name + ".metadata.xml");
if (item.StaticDatum.Count == 0)
return;
var fieldMetaData = item.Fields.SelectMany(x => x.FieldMetadata).ToList();
if (item.EntityMetadata.Count == 0 && fieldMetaData.Count == 0)
return;
var document = new XmlDocument();
document.LoadXml(@"<configuration type=""entity.metadata"" id=""" + item.Id + @"""></configuration>");
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
foreach (var metadata in item.EntityMetadata)
{
var metaDataNode = XmlHelper.AddElement(document.DocumentElement, "metadata");
XmlHelper.AddAttribute(metaDataNode, "key", metadata.Key);
XmlHelper.AddAttribute(metaDataNode, "value", metadata.Value);
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
//Metadata for fields
var metadataColumnsNodes = XmlHelper.AddElement((XmlElement)document.DocumentElement, "fieldset") as XmlElement;
XmlHelper.AddLineBreak((XmlElement)metadataColumnsNodes);
foreach (var fmd in fieldMetaData)
{
var fmdNode = XmlHelper.AddElement(metadataColumnsNodes, "metadata");
XmlHelper.AddAttribute(fmdNode, "columnid", fmd.Field.Id);
XmlHelper.AddAttribute(fmdNode, "key", fmd.Key);
XmlHelper.AddAttribute(fmdNode, "value", fmd.Value);
XmlHelper.AddLineBreak((XmlElement)metadataColumnsNodes);
}
}
WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
}
示例5: SaveEntityStaticData
private static void SaveEntityStaticData(string folder, Entity item, List<string> generatedFileList)
{
var f = Path.Combine(folder, item.Name + ".staticdata.xml");
if (item.StaticDatum.Count == 0)
return;
var document = new XmlDocument();
document.LoadXml(@"<configuration type=""entity.staticdata"" id=""" + item.Id + @"""></configuration>");
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
foreach (var data in item.StaticDatum)
{
var dataNode = XmlHelper.AddElement(document.DocumentElement, "data");
XmlHelper.AddAttribute(dataNode, "columnkey", data.ColumnKey);
XmlHelper.AddAttribute(dataNode, "value", data.Value);
XmlHelper.AddAttribute(dataNode, "orderkey", data.OrderKey);
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
}
WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
}
示例6: SaveModules
private static void SaveModules(string folder, Function item, List<string> generatedFileList)
{
var document = new XmlDocument();
document.LoadXml(@"<configuration type=""function.modules"" id=""" + item.Id + @"""></configuration>");
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
foreach (var module in item.Modules)
{
var newNode = XmlHelper.AddElement(document.DocumentElement, "map");
XmlHelper.AddAttribute(newNode, "module", module.Id);
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
}
var f = Path.Combine(folder, item.Name + ".modules.xml");
WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
}
示例7: SaveEntityComposites
private static void SaveEntityComposites(string folder, Entity item, List<string> generatedFileList)
{
var document = new XmlDocument();
document.LoadXml(@"<configuration type=""composite"" id=""" + item.Id + @"""></configuration>");
if (item.Composites.Count == 0)
return;
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
foreach (var composite in item.Composites)
{
var indexNode = XmlHelper.AddElement(document.DocumentElement, "composite");
XmlHelper.AddLineBreak((XmlElement)indexNode);
XmlHelper.AddCData((XmlElement)indexNode, "summary", composite.Summary);
XmlHelper.AddLineBreak((XmlElement)indexNode);
XmlHelper.AddAttribute(indexNode, "codefacade", composite.CodeFacade);
XmlHelper.AddAttribute(indexNode, "name", composite.Name);
XmlHelper.AddAttribute(indexNode, "isgenerated", composite.IsGenerated);
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
//Process the columns
var columnsNodes = XmlHelper.AddElement((XmlElement)indexNode, "columnset") as XmlElement;
XmlHelper.AddLineBreak((XmlElement)columnsNodes);
foreach (var column in composite.Fields)
{
var indexColumnNode = XmlHelper.AddElement(columnsNodes, "column");
XmlHelper.AddAttribute(indexColumnNode, "fieldid", column.FieldId);
XmlHelper.AddLineBreak((XmlElement)columnsNodes);
}
}
var f = Path.Combine(folder, item.Name + ".composites.xml");
WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
}
示例8: SaveEntityIndexes
private static void SaveEntityIndexes(string folder, Entity item, List<string> generatedFileList)
{
var document = new XmlDocument();
document.LoadXml(@"<configuration type=""entity.indexes"" id=""" + item.Id + @"""></configuration>");
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
foreach (var index in item.Indexes)
{
var indexNode = XmlHelper.AddElement(document.DocumentElement, "index");
XmlHelper.AddLineBreak((XmlElement)indexNode);
XmlHelper.AddCData((XmlElement)indexNode, "summary", index.Summary);
XmlHelper.AddLineBreak((XmlElement)indexNode);
XmlHelper.AddAttribute(indexNode, "id", index.Id);
XmlHelper.AddAttribute(indexNode, "clustered", index.Clustered);
XmlHelper.AddAttribute(indexNode, "importedname", index.ImportedName);
XmlHelper.AddAttribute(indexNode, "indextype", index.IndexType.ToString("d"));
XmlHelper.AddAttribute(indexNode, "isunique", index.IsUnique);
XmlHelper.AddLineBreak((XmlElement)document.DocumentElement);
//Process the columns
var indexColumnsNodes = XmlHelper.AddElement((XmlElement)indexNode, "indexcolumnset") as XmlElement;
XmlHelper.AddLineBreak((XmlElement)indexColumnsNodes);
foreach (var indexColumn in index.IndexColumns)
{
var indexColumnNode = XmlHelper.AddElement(indexColumnsNodes, "column");
XmlHelper.AddAttribute(indexColumnNode, "id", indexColumn.Id);
XmlHelper.AddAttribute(indexColumnNode, "ascending", indexColumn.Ascending);
XmlHelper.AddAttribute(indexColumnNode, "fieldid", indexColumn.FieldID);
XmlHelper.AddAttribute(indexColumnNode, "sortorder", indexColumn.SortOrder);
XmlHelper.AddLineBreak((XmlElement)indexColumnsNodes);
}
}
var f = Path.Combine(folder, item.Name + ".indexes.xml");
WriteFileIfNeedBe(f, document.ToIndentedString(), generatedFileList);
}
示例9: WriteFileIfNeedBe
private static void WriteFileIfNeedBe(string fileName, string contents, List<string> generatedFileList)
{
if (fileName.ToLower().EndsWith(".xml"))
{
generatedFileList.Add(fileName);
try
{
//Load formatted original XML
var origXML = string.Empty;
if (File.Exists(fileName))
{
var xmlText = File.ReadAllText(fileName);
if (!string.IsNullOrEmpty(xmlText))
{
var documentCheck = new XmlDocument();
documentCheck.LoadXml(xmlText);
origXML = documentCheck.ToIndentedString();
}
}
//Load formatted new XML
var newXML = string.Empty;
{
var documentCheck = new XmlDocument();
documentCheck.LoadXml(contents);
newXML = documentCheck.ToIndentedString();
}
if (origXML == newXML)
return;
else
contents = newXML;
}
catch (Exception ex)
{
//If there is an error then process like a non-XML file
//Do Nothing
}
}
else
{
//Check if this is the same content and if so do nothing
generatedFileList.Add(fileName);
if (File.Exists(fileName))
{
var t = File.ReadAllText(fileName);
if (t == contents)
return;
}
}
File.WriteAllText(fileName, contents);
System.Windows.Forms.Application.DoEvents();
}
示例10: BuildModelList
private List<nHydrateGeneratorProject> BuildModelList(nHydrateModel model, Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram, Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
{
var genList = new List<nHydrateGeneratorProject>();
if (model.UseModules)
{
foreach (var module in model.Modules)
{
var genProject = new nHydrateGeneratorProject();
genList.Add(genProject);
var root = CreatePOCOModel(model, diagram, module);
root.SetKey(module.Id.ToString());
root.GeneratorProject = genProject;
genProject.RootController.Object = root;
var fi = new System.IO.FileInfo(docData.FileName);
genProject.FileName = docData.FileName + "." + module.Name + ".generating";
var document = new System.Xml.XmlDocument();
document.LoadXml("<modelRoot guid=\"" + module.Id + "\" type=\"nHydrate.Generator.nHydrateGeneratorProject\" assembly=\"nHydrate.Generator.dll\"><ModelRoot></ModelRoot></modelRoot>");
((nHydrate.Generator.Common.GeneratorFramework.IXMLable)root).XmlAppend(document.DocumentElement.ChildNodes[0]);
System.IO.File.WriteAllText(genProject.FileName, document.ToIndentedString());
ProcessRenamed(genProject.FileName + ".sql.lastgen", root);
root.RemovedTables.AddRange(model.RemovedTables);
root.RemovedViews.AddRange(model.RemovedViews);
root.RemovedStoredProcedures.AddRange(model.RemovedStoredProcedures);
root.RemovedFunctions.AddRange(model.RemovedFunctions);
//Remove associative tables since they cause issues if they exist
root.RemovedTables.AddRange(model.Entities.Where(x => x.IsAssociative && x.IsGenerated).Select(x => x.Name));
//Remove non-generated items from the project
root.RemovedTables.AddRange(model.Entities.Where(x => !x.IsGenerated).Select(x => x.Name));
root.RemovedTables.AddRange(model.Views.Where(x => !x.IsGenerated).Select(x => x.Name));
root.RemovedTables.AddRange(model.StoredProcedures.Where(x => !x.IsGenerated).Select(x => x.Name));
root.RemovedTables.AddRange(model.Functions.Where(x => !x.IsGenerated).Select(x => x.Name));
//Remove EnumOnly type-tables from the project
root.RemovedTables.AddRange(model.Entities.Where(x => x.TypedEntity == TypedEntityConstants.EnumOnly && x.IsGenerated).Select(x => x.Name));
}
}
else
{
var genProject = new nHydrateGeneratorProject();
genList.Add(genProject);
var root = CreatePOCOModel(model, diagram, null);
root.SetKey(model.Id.ToString());
root.GeneratorProject = genProject;
genProject.RootController.Object = root;
var fi = new System.IO.FileInfo(docData.FileName);
genProject.FileName = docData.FileName + ".generating";
var document = new System.Xml.XmlDocument();
document.LoadXml("<modelRoot guid=\"" + model.Id + "\" type=\"nHydrate.Generator.nHydrateGeneratorProject\" assembly=\"nHydrate.Generator.dll\"><ModelRoot></ModelRoot></modelRoot>");
((nHydrate.Generator.Common.GeneratorFramework.IXMLable)root).XmlAppend(document.DocumentElement.ChildNodes[0]);
System.IO.File.WriteAllText(genProject.FileName, document.ToIndentedString());
ProcessRenamed(genProject.FileName + ".sql.lastgen", root);
root.RemovedTables.AddRange(model.RemovedTables);
root.RemovedViews.AddRange(model.RemovedViews);
root.RemovedStoredProcedures.AddRange(model.RemovedStoredProcedures);
root.RemovedFunctions.AddRange(model.RemovedFunctions);
//Remove associative tables since they cause issues if they exist
root.RemovedTables.AddRange(model.Entities.Where(x => x.IsAssociative && x.IsGenerated).Select(x => x.Name));
//Remove non-generated items from the project
root.RemovedTables.AddRange(model.Entities.Where(x => !x.IsGenerated).Select(x => x.Name));
root.RemovedTables.AddRange(model.Views.Where(x => !x.IsGenerated).Select(x => x.Name));
root.RemovedTables.AddRange(model.StoredProcedures.Where(x => !x.IsGenerated).Select(x => x.Name));
root.RemovedTables.AddRange(model.Functions.Where(x => !x.IsGenerated).Select(x => x.Name));
//Remove EnumOnly type-tables from the project
root.RemovedTables.AddRange(model.Entities.Where(x => x.TypedEntity == TypedEntityConstants.EnumOnly && x.IsGenerated).Select(x => x.Name));
}
return genList;
}