Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's actually two parts to your problem that I can.</p> <ol> <li>Get a book object from known Id</li> <li>Create a new book object</li> </ol> <p>To retrieve the object:</p> <pre><code> public class Book { public Book(string id, string name, decimal price) { Id = id; Name = name; Price = price; } public string Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } } </code></pre> <p>To load the book with known Id into the object:</p> <pre><code>XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(_path); XmlNode xmlNode = xmlDocument.SelectSingleNode(@"//book[@id='" + id + "']"); return xmlNode == null ? new Book(id, string.Empty, 0) : new Book(id, xmlNode.Attributes["name"].Value, decimal.Parse(xmlNode.Attributes["price"].Value)); </code></pre> <p>To create a new book element:</p> <pre><code>XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(_path); XmlElement newBook = xmlDocument.CreateElement("book"); newBook.SetAttribute("id", book.Id); newBook.SetAttribute("name", book.Name); newBook.SetAttribute("price", book.Price.ToString()); xmlDocument.DocumentElement.AppendChild(newBook); xmlDocument.Save(_path); </code></pre> <p>Where _path is the path to your XML document.</p> <p>I hope this helps. Also remember that XmlDocument is an in-memory or cached tree representation of an XML document. It is somewhat resource-intensive, if you have a large XML document and not enough memory to consume, use XmlReader and XmlWriter for better performance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload