System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
xdoc.XmlResolver = null;
//load the xml file
System.Xml.XmlElement Node = (System.Xml.XmlElement)xdoc.DocumentElement.SelectSingleNode("//configuration/connectionStrings/add[@name=\"Application.Properties.Settings.DBConnectionString\"]");
if (Node != null)
//key found, set the value
Node.Attributes.GetNamedItem("Source").Value = "C:\DataDabe\DB.mdb";
//finally, save the new version of the config file
In the WCF I write a datatable to a stringreader and return the string to the UI. In the UI I need to turn the string into an object (Telerik datatable class) which requires that I read the elements to create the columns and the data to populate the rows.
Problem is when the data has null values the xml does not get a full set of elements, the table is invalid in the UI. To solve this I want to include the schema in the string passed to the UI.
However I cannot work out how to get the schema out of the xDocument. This receives the string and creates the xDocument, I then need to get the schema to create the columns
void GenericProcedureCompleted(object sender, GenericProcedureCompletedEventArgs e)
svcClient.GenericProcedureCompleted -= new EventHandler<GenericProcedureCompletedEventArgs>(GenericProcedureCompleted);
System.IO.StringReader sr = new System.IO.StringReader(e.Result);
XDocument xDoc = XDocument.Load(sr);
This is currently using the elements to create the table
XmlNodeList myNodeList=xmlDoc.SelectNodes(myXPath); // This gives you the collection of Address nodes with Name as Homepage
foreach (myXmlNode in xmlNodeList)
MessageBox.Show(myXmlNode.Value); // Displays the address
In order to use SelectNodes to select nodes and attributes that have a namespace prefix, you need an XmlNamespaceManager that knows about the namespace and prefix. Unfortunately, I haven't found a way to access a pre-populated XmlNamespaceManager or to automagically populate one from an XmlDocument.
According to the documentation, XmlReaders use XmlNamespaceManagers, so after I load a document with an XmlReader I should be able to copy the XmlReader's XmlNamespaceManager -- but it shows null (and requires Reflection). I should be able to pass an XmlNamespaceManager to an XmlReader and the XmlReader should use it -- but it still shows null.
I've gone through a bunch of documentation and searching articles here and elsewhere hasn't yielded a silver bullet. They all show code calling AddNamespace to add specific namespaces -- I need it to be dynamic.
So I'm trying to roll my own. At this point, I'm loading the document with an XmlReader and then trying to query any attributes in the xmlns namespace, I should then be able to populate an XmlNamespaceManager with AddNamespace.
The code, as I have it now (I've tried several variations of the XPath) is:
System.Xml.XmlNamespaceManager result =
new System.Xml.XmlNamespaceManager ( Document.NameTable ) ;
System.Xml.XmlNodeList nodes = Document.DocumentElement.SelectNodes ( "//@xmlns:*" , result ) ;
This should yield all the attributes in the xmlns namespace (and the document contains one), but the list comes up empty.
0) Can anyone provide me with an XPath that will do what I want?
1) Does anyone know how to get a pre-populated XmlNamespaceManager from an XmlReader or an XmlDocument?