本文整理匯總了C#中System.Xml.XmlNodeReader.MoveToContent方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlNodeReader.MoveToContent方法的具體用法?C# XmlNodeReader.MoveToContent怎麽用?C# XmlNodeReader.MoveToContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlNodeReader
的用法示例。
在下文中一共展示了XmlNodeReader.MoveToContent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Read
public static void Read(XmlDocument xml)
{
List<DecModel> list = new List<DecModel>();
XNamespace ns = "HTTP://CLIS.HB_DEC";
using (var nodeReader = new XmlNodeReader(xml))
{
nodeReader.MoveToContent();
XDocument xdoc= XDocument.Load(nodeReader);
var seqNo = xdoc.Descendants(ns + "SEQ_NO").First().Value;
var entryId = xdoc.Descendants(ns + "ENTRY_ID").First().Value;
var ieFlag = xdoc.Descendants(ns + "I_E_FLAG").First().Value;
foreach (var element in xdoc.Descendants(ns + "HB_DEC_LIST"))
{
Console.WriteLine(element.Element(ns + "COP_G_NO").Value, element.Element(ns + "QTY").Value);
DecModel item = new DecModel();
item.EntryId = entryId;
item.SeqNo = seqNo;
item.IEFlag = ieFlag;
item.GNo = element.Element(ns + "COP_G_NO").Value;
item.Qty = Convert.ToDecimal(element.Element(ns + "QTY").Value);
list.Add(item);
}
if (list.Count > 0)
{
SqlHelper.Insert(list);
}
}
}
示例2: GetPosts
public List<WpPost> GetPosts(WpImportOptions options)
{
Item mediaInnerItem = _db.GetItem(_mediaItemId);
if (mediaInnerItem == null)
{
Logger.Error(String.Format("Media item for import could not be found (id: {0}, db: {1})", _mediaItemId, _db.Name));
return new List<WpPost>(0);
}
MediaItem mediaItem = new MediaItem(mediaInnerItem);
XmlDocument xmdDoc = new XmlDocument();
var mediaStream = MediaManager.GetMedia(mediaItem).GetStream();
if (mediaStream == null || mediaStream.MimeType != "text/xml")
{
Logger.Error(String.Format("MediaStream for imported item is null or uploaded file has is incorrect format (id: {0}, db: {1})", _mediaItemId, _db.Name));
return new List<WpPost>(0);
}
xmdDoc.Load(mediaStream.Stream);
using (var nodeReader = new XmlNodeReader(xmdDoc))
{
nodeReader.MoveToContent();
var xDocument = XDocument.Load(nodeReader);
var posts = (from item in xDocument.Descendants("item")
select new WpPost(item, options)).ToList();
return posts;
}
}
示例3: ToXDocument
public static XDocument ToXDocument(this XmlDocument xmlDocument)
{
using (var nodeReader = new XmlNodeReader(xmlDocument)) {
nodeReader.MoveToContent();
return XDocument.Load(nodeReader);
}
}
示例4: Read
public static void Read(XmlDocument xml)
{
List<DecModel> list = new List<DecModel>();
//XNamespace ns = "HTTP://CLIS.HB_DEC";
using (var nodeReader = new XmlNodeReader(xml))
{
nodeReader.MoveToContent();
XDocument xdoc= XDocument.Load(nodeReader);
var orderno = xdoc.Descendants("ERP_OBJECT_ID").First().Value;
var preno = xdoc.Descendants("PRE_GATEPASS_NO").First().Value;
var gatepassno = xdoc.Descendants("GATEPASS_NO").First().Value;
if (orderno.Length > 0 && gatepassno.Length > 0)
{
SqlHelper.UpdateCLSStatus(orderno, gatepassno
);
}
}
}
示例5: SerializeXmlNode
private string SerializeXmlNode(XmlNode node)
{
string json = JsonConvert.SerializeXmlNode(node, Formatting.Indented);
XmlNodeReader reader = new XmlNodeReader(node);
#if !NET20
XObject xNode;
if (node is XmlDocument)
{
xNode = XDocument.Load(reader);
}
else if (node is XmlAttribute)
{
XmlAttribute attribute = (XmlAttribute) node;
xNode = new XAttribute(XName.Get(attribute.LocalName, attribute.NamespaceURI), attribute.Value);
}
else
{
reader.MoveToContent();
xNode = XNode.ReadFrom(reader);
}
string linqJson = JsonConvert.SerializeXNode(xNode, Formatting.Indented);
Assert.AreEqual(json, linqJson);
#endif
return json;
}
示例6: ToXDocument
public static XDocument ToXDocument(this XmlDocument xmlDocument, LoadOptions options = LoadOptions.None)
{
using (var nodeReader = new XmlNodeReader(xmlDocument))
{
nodeReader.MoveToContent();
return XDocument.Load(nodeReader, options);
}
}
示例7: ToXDocument
/// <summary>
/// Converts a <see cref="XmlDocument"/> instance into a <see cref="XDocument"/> instance.
/// </summary>
/// <param name="input">The <see cref="XmlDocument"/> instance to convert.</param>
/// <returnsAn <see cref="XDocument"/> instance containing the data from the input <see cref="XmlDocument"/>.</returns>
public static XDocument ToXDocument(this XmlDocument input)
{
using (var xmlStream = new XmlNodeReader(input))
{
xmlStream.MoveToContent();
return XDocument.Load(xmlStream);
}
}
示例8: ToXElement
/// <summary>
/// Converts an <see cref="System.Xml.XmlNode"/> to a <see cref="System.Xml.Linq.XElement"/>
/// </summary>
/// <param name="node">Node to convert</param>
/// <returns>Converted node</returns>
public static XElement ToXElement(this XmlNode node)
{
using (var x = new XmlNodeReader(node))
{
x.MoveToContent();
return XElement.Load(x);
}
}
示例9: ToXDocument
public static XElement ToXDocument(this XmlDocument xmlDocument)
{
using (var nodeReader = new XmlNodeReader(xmlDocument))
{
nodeReader.MoveToContent();
var xDoc = XDocument.Load(nodeReader);
return XElement.Parse(xDoc.ToString());
}
}
示例10: ReadTextElementAsTrimmedString
internal static string ReadTextElementAsTrimmedString(XmlElement element)
{
if (element == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
XmlReader reader = new XmlNodeReader(element);
reader.MoveToContent();
return XmlUtil.Trim(reader.ReadElementContentAsString());
}
示例11: CreateGenerator
public virtual NvdlValidatorGenerator CreateGenerator (NvdlValidate validate, string schemaType, NvdlConfig config)
{
this.validate = validate;
this.schema_type = schemaType;
this.config = config;
XmlReader schema = null;
// FIXME: we need a bit more strict check.
if (schemaType.Length < 5 ||
!schemaType.EndsWith ("xml") ||
Char.IsLetter (schemaType, schemaType.Length - 4))
return null;
string schemaUri = validate.SchemaUri;
XmlElement schemaBody = validate.SchemaBody;
if (schemaUri != null) {
if (schemaBody != null)
throw new NvdlCompileException ("Both 'schema' attribute and 'schema' element are specified in a 'validate' element.", validate);
schema = GetSchemaXmlStream (schemaUri, config, validate);
}
else if (validate.SchemaBody != null) {
XmlReader r = new XmlNodeReader (schemaBody);
r.MoveToContent ();
r.Read (); // Skip "schema" element
r.MoveToContent ();
if (r.NodeType == XmlNodeType.Element)
schema = r;
else
schema = GetSchemaXmlStream (r.ReadString (), config, validate);
}
if (schema == null)
return null;
return CreateGenerator (schema, config);
}
示例12: Main
static void Main(string[] args)
{
var artists = new List<string>();
var albums = new List<string>();
var catalogFilePath = "../../../../catalog.xml";
XmlDocument doc = new XmlDocument();
doc.Load(catalogFilePath);
using (XmlNodeReader reader = new XmlNodeReader(doc))
{
reader.MoveToContent();
reader.ReadToDescendant("album");
while (reader.Read())
{
var albumName = reader.ReadInnerXml();
albums.Add(albumName);
var artist = reader.ReadInnerXml();
artists.Add(artist);
reader.ReadToFollowing("album");
}
}
string albumFilePath = "../../album.xml";
Encoding encoding = Encoding.GetEncoding("windows-1251");
using (XmlTextWriter writer = new XmlTextWriter(albumFilePath, encoding))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("albums");
for (int i = 0, len = artists.Count; i < len; i++)
{
WriteAlbum(writer, albums[i], artists[i]);
}
writer.WriteEndDocument();
}
Console.WriteLine("Document {0} created.", albumFilePath);
}
示例13: btnConvert_Click
private void btnConvert_Click(object sender, EventArgs e)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(txtFileName.Text);
XElement result = null;
using (XmlNodeReader nodeReader = new XmlNodeReader(doc))
{
// the reader must be in the Interactive state in order to
// Create a LINQ to XML tree from it.
nodeReader.MoveToContent();
XElement xRoot = XElement.Load(nodeReader);
result = DeployConverter.DeployConverter.ToUDSDeployElement(xRoot);
}
if (result != null)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.DefaultExt = "csml";
string sourcepath = txtFileName.Text;
FileInfo file = new FileInfo(sourcepath);
sfd.InitialDirectory = file.DirectoryName;
sfd.FileName = Path.Combine(file.DirectoryName, "new.csml");
DialogResult dr = sfd.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
XmlDocument d = new XmlDocument();
d.LoadXml(result.ToString());
d.Save(sfd.FileName);
MessageBox.Show("轉換完成", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show("轉換過程中發生錯誤 : \n" + ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例14: DownloadBucket
public static void DownloadBucket(string url, string targetPath, int parallelDownloads = 32)
{
Dictionary<string, string> etags;
var di = new DirectoryInfo(targetPath);
using (var s = di.GetFile("bucket.bson").Open(FileMode.OpenOrCreate))
{
using (var br = new BsonReader(s))
{
var se = new JsonSerializer();
etags = se.Deserialize<Dictionary<string, string>>(br) ?? new Dictionary<string, string>();
}
}
XDocument doc;
XNamespace xmlns = "http://s3.amazonaws.com/doc/2006-03-01/";
Console.Write("Loading S3 bucket... ");
while (true)
{
var xdoc = new XmlDocument();
xdoc.Load(url);
var xnr = new XmlNodeReader(xdoc);
xnr.MoveToContent();
doc = XDocument.Load(xnr);
Console.WriteLine("found {0} items", doc.Descendants(xmlns + "Contents").Count());
if (!doc.Descendants(xmlns + "Contents").Any())
{
continue;
}
break;
}
var actionsCompleted = 0;
var actions = new List<Tuple<string, string>>();
Action<Tuple<string, string>> downloadingAction = t =>
{
var etag = t.Item1;
var path = t.Item2;
var rpath = path.Replace('/', Path.DirectorySeparatorChar);
var fi = new FileInfo(Path.Combine(di.FullName + Path.DirectorySeparatorChar, rpath));
if (fi.Directory != null && !fi.Directory.Exists)
fi.Directory.Create();
else if (fi.Exists)
fi.Delete();
var b = new UriBuilder(url);
b.Path = b.Path.TrimEnd('/') + "/" + path;
while (true)
{
try
{
File.Move(Http.Download(b.Uri.ToString()), fi.FullName);
}
catch
{
continue;
}
break;
}
lock (etags)
{
etags[path] = etag;
actionsCompleted++;
Console.Write("Downloading... ({0}/{1}, {2}%)\r", actionsCompleted, actions.Count, Math.Round(100 * (float)actionsCompleted / actions.Count, 0));
}
};
foreach (var content in doc.Descendants(xmlns + "Contents"))
{
var xkey = content.Element(xmlns + "Key");
var xetag = content.Element(xmlns + "ETag");
if (xkey == null || xetag == null)
continue;
// Key as relative path
var relpath = xkey.Value;
// Compare etags
var etag = xetag.Value.Trim('"');
if (!etags.ContainsKey(relpath))
etags.Add(relpath, null);
if (etags[relpath] == etag)
continue; // File or directory not changed
// Local path
var rellpath = relpath.Replace('/', Path.DirectorySeparatorChar);
// Check if directory
if (relpath.EndsWith("/")) // is a directory
Directory.CreateDirectory(Path.Combine(di.FullName + Path.DirectorySeparatorChar, rellpath));
else
{
actions.Add(new Tuple<string, string>(etag, relpath));
//.........這裏部分代碼省略.........
示例15: XmlDocumentToXDocument
private XDocument XmlDocumentToXDocument(XmlDocument xml)
{
using (var nodeReader = new XmlNodeReader(xml))
{
nodeReader.MoveToContent();
return XDocument.Load(nodeReader);
}
}