why does the Xdocument give me a utf16 declaration?

StringWriter advertises itself as using UTF-16. It’s easy to fix though: public class Utf8StringWriter : StringWriter { public override Encoding Encoding { get { return Encoding.UTF8; } } } That should be enough in your particular case. A rather more well-rounded implementation would: Have constructors matching those in StringWriter Allow the encoding to be specified … Read more

xml error: Non white space characters cannot be added to content

It looks like you’re attempting to load an XML file into an XDocument, but to do so you need to call XDocument.Load(“C:\\temp\\contacts.xml”); – you can’t pass an XML file into the constructor. You can also load a string of XML with XDocument.Parse(stringXml);. Change your first line to: var doc = XDocument.Load(“c:\\temp\\contacts.xml”); And it will work. … Read more

get line number for XElement here

XElement (actually XObject) implements the IXmlLineInfo interface, so you can use it: IXmlLineInfo info = category; int lineNumber = info.LineNumber; Note that line information is not always available, you need to call the HasLineInfo method to check if the information is available. You can specify LoadOptions.SetLineInfo when you load the document with XDocument.Load

How to Get XML Node from XDocument

test.xml: <?xml version=”1.0″ encoding=”utf-8″?> <Contacts> <Node> <ID>123</ID> <Name>ABC</Name> </Node> <Node> <ID>124</ID> <Name>DEF</Name> </Node> </Contacts> Select a single node: XDocument XMLDoc = XDocument.Load(“test.xml”); string id = “123”; // id to be selected XElement Contact = (from xml2 in XMLDoc.Descendants(“Node”) where xml2.Element(“ID”).Value == id select xml2).FirstOrDefault(); Console.WriteLine(Contact.ToString()); Delete a single node: XDocument XMLDoc = XDocument.Load(“test.xml”); string id … Read more

How do I use XPath with a default namespace with no prefix?

The configuration element is in the unnamed namespace, and the MyNode is bound to the lcmp namespace without a namespace prefix. This XPATH statement will allow you to address the MyNode element without having declared the lcmp namespace or use a namespace prefix in your XPATH: /configuration/*[namespace-uri()=’lcmp’ and local-name()=’MyNode’] It matches any element that is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)