本文整理汇总了C#中System.Xml.Linq.XDocument类的典型用法代码示例。如果您正苦于以下问题:C# XDocument类的具体用法?C# XDocument怎么用?C# XDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XDocument类属于System.Xml.Linq命名空间,在下文中一共展示了XDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetXml
public string GetXml(bool validate)
{
XNamespace ns = "http://sd.ic.gc.ca/SLDR_Schema_Definition_en";
var spectrum_licences = getLicences();
XDocument doc = new XDocument(new XElement("spectrum_licence_data_registry", spectrum_licences));
foreach (XElement e in doc.Root.DescendantsAndSelf())
{
if (e.Name.Namespace == "")
e.Name = ns + e.Name.LocalName;
}
var errors = new StringBuilder();
if (validate)
{
XmlSchemaSet set = new XmlSchemaSet();
var schema = getMainSchema();
set.Add(null, schema);
doc.Validate(set, (sender, args) => { errors.AppendLine(args.Message); });
}
//return errors.Length > 0 ? errors.ToString() : doc.ToString();
var result = errors.Length > 0 ? "Validation Errors: " + errors.ToString() : getDocumentAsString(doc);
return result;
}
示例2: ImportTexturesFromXml
private void ImportTexturesFromXml(XDocument xml)
{
var texData = xml.Root.Elements("ImportTexture");
foreach (var tex in texData)
{
string name = tex.Attribute("filename").Value;
string data = tex.Value;
// The data is gzip compressed base64 string. We need the raw bytes.
//byte[] bytes = ImportUtils.GzipBase64ToBytes(data);
byte[] bytes = ImportUtils.Base64ToBytes(data);
// Save and import the texture asset
{
string pathToSave = GetTextureAssetPath(name);
ImportUtils.ReadyToWrite(pathToSave);
File.WriteAllBytes(pathToSave, bytes);
AssetDatabase.ImportAsset(pathToSave, ImportAssetOptions.ForceSynchronousImport);
}
// Create a material if needed in prepartion for the texture being successfully imported
{
string materialPath = GetMaterialAssetPath(name);
Material material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;
if (material == null)
{
// We need to create the material afterall
// Use our custom shader
material = new Material(Shader.Find("Tiled/TextureTintSnap"));
ImportUtils.ReadyToWrite(materialPath);
AssetDatabase.CreateAsset(material, materialPath);
}
}
}
}
示例3: VersionedModel
public VersionedModel(XDocument model, string version = null)
{
DebugCheck.NotNull(model);
_model = model;
_version = version;
}
示例4: GetXDocument
public static XDocument GetXDocument(this OpenXmlPart part)
{
try
{
XDocument partXDocument = part.Annotation<XDocument>();
if (partXDocument != null)
return partXDocument;
using (Stream partStream = part.GetStream())
{
if (partStream.Length == 0)
{
partXDocument = new XDocument();
partXDocument.Declaration = new XDeclaration("1.0", "UTF-8", "yes");
}
else
using (XmlReader partXmlReader = XmlReader.Create(partStream))
partXDocument = XDocument.Load(partXmlReader);
}
part.AddAnnotation(partXDocument);
return partXDocument;
}
catch (Exception e)
{
throw e;
}
}
示例5: LessonParse
//Возвращает список предметов
public static string[] LessonParse(XDocument Lessons, string Class)
{
string[] New = new string[0];
foreach (string Lesson in Lessons.Element("Lessons").Elements(Class).Elements("LessIds"))
New = HelpDeriver(Lesson);
return New;
}
示例6: DelParse
//Возвращает список текстов класса если DataType = text и дат если date
public static List<string> DelParse(XDocument Lessons, string Class, string LessonType, string DataType)
{
List<string> Data = new List<string>();
foreach (string Text in Lessons.Descendants(Class).Elements(LessonType).Elements(DataType)) //Можно получить Class и lesson
Data.Add(TextDeriver(Text)); //Мы получаем одну строку, поэтому однострочный дерайвер
return Data;
}
示例7: GetIsSilverlight
static bool GetIsSilverlight(XDocument xDocument)
{
var targetFrameworkIdentifier = xDocument.BuildDescendants("TargetFrameworkIdentifier")
.Select(c => c.Value)
.FirstOrDefault();
return (string.Equals(targetFrameworkIdentifier, "Silverlight", StringComparison.OrdinalIgnoreCase));
}
示例8: LastFMTrackInfo
public LastFMTrackInfo(XDocument xDoc)
{
if (xDoc.Root == null) return;
var track = xDoc.Root.Element("track");
if (track == null) return;
Identifier = (int) track.Element("id");
TrackTitle = (string) track.Element("name");
MusicBrainzId = (string) track.Element("mbid");
TrackURL = (string) track.Element("url");
Duration = (int) track.Element("duration");
Listeners = (int) track.Element("listeners");
Playcount = (int) track.Element("playcount");
var artistElement = track.Element("artist");
if (artistElement != null) ArtistName = (string) artistElement.Element("name");
TopTags = (from tagElement in track.Descendants("tag")
let tagName = (string) tagElement.Element("name")
let tagURL = (string) tagElement.Element("url")
select new LastFMTag(tagName, tagURL)
).ToList();
var albumElement = track.Element("album");
if (albumElement != null)
{
Images = (from i in albumElement.Elements("image")
select new LastFMImage(
LastFMImage.GetImageSizeEnum((string) i.Attribute("size")),
(string) i
)
).ToList();
}
}
示例9: GetReferences
private static IEnumerable<ReferenceDescriptor> GetReferences(XDocument document) {
var assemblyReferences = document
.Elements(ns("Project"))
.Elements(ns("ItemGroup"))
.Elements(ns("Reference"))
.Where(c => c.Attribute("Include") != null)
.Select(c => {
string path = null;
XElement attribute = c.Elements(ns("HintPath")).FirstOrDefault();
if (attribute != null) {
path = attribute.Value;
}
return new ReferenceDescriptor {
SimpleName = ExtractAssemblyName(c.Attribute("Include").Value),
FullName = c.Attribute("Include").Value,
Path = path,
ReferenceType = ReferenceType.Library
};
});
var projectReferences = document
.Elements(ns("Project"))
.Elements(ns("ItemGroup"))
.Elements(ns("ProjectReference"))
.Attributes("Include")
.Select(c => new ReferenceDescriptor {
SimpleName = Path.GetFileNameWithoutExtension(c.Value),
FullName = Path.GetFileNameWithoutExtension(c.Value),
Path = c.Value,
ReferenceType = ReferenceType.Project
});
return assemblyReferences.Union(projectReferences);
}
示例10: GetXDocument
public XDocument GetXDocument()
{
List<PortSetting> list = new List<PortSetting>()
{
new PortSetting()
{
Name ="InputPort",
Value=""
},
new PortSetting()
{
Name ="OutputPort",
Value=""
},
};
XDocument xDoc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("System Setting"),
new XElement("Settings",
list.Select(x => (new XElement("Setting",
new XElement("Name", x.Name),
new XElement("Value", x.Value))))
));
return xDoc;
}
示例11: XmlLoggerBasicTest
public void XmlLoggerBasicTest()
{
var path = @"x:\deployments\1234\log.xml";
var fileSystem = new Mock<IFileSystem>();
var file = new Mock<FileBase>();
var id = Guid.NewGuid().ToString();
var message = Guid.NewGuid().ToString();
var doc = new XDocument(new XElement("entries",
new XElement("entry",
new XAttribute("time", "2013-12-08T01:58:24.0247841Z"),
new XAttribute("id", id),
new XAttribute("type", "0"),
new XElement("message", message)
)
));
var mem = new MemoryStream();
doc.Save(mem);
// Setup
fileSystem.SetupGet(f => f.File)
.Returns(file.Object);
file.Setup(f => f.Exists(path))
.Returns(true);
file.Setup(f => f.OpenRead(path))
.Returns(() => { mem.Position = 0; return mem; });
// Test
var logger = new XmlLogger(fileSystem.Object, path, Mock.Of<IAnalytics>());
var entries = logger.GetLogEntries();
// Assert
Assert.Equal(1, entries.Count());
Assert.Equal(id, entries.First().Id);
Assert.Equal(message, entries.First().Message);
}
示例12: Save
public static void Save(string path)
{
var document = new XDocument();
var root = new XElement("PrettyCheckoutDatabase", new XAttribute("Version", DataReaderFileVersion));
foreach (var product in Program.Environment.Products)
{
var element = new XElement("Product");
element.Add(new XAttribute("ID", product.Index));
element.Add(new XAttribute("Name", product.Name));
element.Add(new XAttribute("Price", product.Price));
element.Add(new XAttribute("PriceN", product.PriceN));
element.Add(new XAttribute("Vat", product.Vat));
element.Add(new XElement("Description", new XCData(product.Description == null ? string.Empty : product.Description)));
root.Add(element);
}
document.Add(root);
try
{
document.Save(path);
}
catch (Exception)
{
MessageBox.Show("Data file could not be saved - " + path);
}
}
示例13: WriteProcessed
/// <summary>
/// Writes the results of XSLT transformation into the specified TextWriter.
/// </summary>
public static void WriteProcessed(string templateName, XsltArgumentList argumentList, XDocument data, TextWriter outStream)
{
using (XmlReader reader = data.CreateReader())
{
GetCompiledTransform(templateName).Transform(reader, argumentList, outStream);
}
}
示例14: GetCertificate
public static X509Certificate2 GetCertificate(XDocument xdoc)
{
var profile = xdoc.Descendants("PublishProfile").Single();
var managementCertbase64String = profile.Attribute("ManagementCertificate").Value;
return new X509Certificate2(Convert.FromBase64String(managementCertbase64String));
}
示例15: GenerateXML
private XDocument GenerateXML()
{
XDocument xml = new XDocument(
new XDeclaration("1.0", "windows-1250", "true"),
new XElement("Zadost",
new XAttribute("Verze", "01"),
new XAttribute("Kod", this.smlouvaID),
new XAttribute("Typ", "Z"),
new XAttribute("Timestamp", this.smlouvaCreateDate.ToString()),
new XElement("NazevFilmu", tbNazevFilmu.Text),
new XElement("NazevSkladby", tbNazevSkladby.Text),
new XElement("AutoriHudby", tbAutoriHudby.Text),
new XElement("AutoriTextu", tbAutoriTextu.Text),
new XElement("Nakladatel", tbNakladatel.Text),
new XElement("Label", tbLabel.Text),
new XElement("ZpracovatelHudby", tbZpracovatelHudby.Text),
new XElement("Subtextar", tbSubtextar.Text),
new XElement("VyrobceReklamnihoSpotu", tbVyrobceReklamy.Text),
new XElement("Zadavatel", tbZadavatel.Text),
new XElement("HudebniStopaz", tbHudebniStopaz.Text),
new XElement("DruhUziti", tbDruhUziti.Text),
new XElement("ZpusobUziti", tbZpusobUziti.Text),
new XElement("SouhlasUdelil", tbSouhlasUdelil.Text),
new XElement("DobaTrvaniLicence", tbDobaTrvaniLicence.Text),
new XElement("Poznamky", tbPoznamka.Text),
new XElement("EmailProPotvrzeni", tbEmailProPotvrzeni.Text)
));
return xml;
}