Search Results

Search found 314 results on 13 pages for 'xmldocument'.

Page 7/13 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • IIS 7.5 can't access file from managed code

    - by Bob
    I am working on a project that is click-once deployed from an IIS 7.5 web server. After installing the parent application (i.e. setting up the IIS site) I am able to hit the url for the click-once app's config file from a remote box. HOWEVER, when I attempt to do the same thing from my app (and the stub app below), I get a 401 Unauthorized. What is the difference between hitting the URL from IE, and from a .NET app? The file and directory itself have full control granted to everyone on the webserver at the moment, and I am an admin on the box. We are using Windows Authentication with NTLM only. Thanks, -Bob Here is the stub app that produces the 401 - Unauthorized when on the doc.Load() line. I can hit the same URL successfully from IE and open the file... static void Main(string[] args) { Console.WriteLine("Config Test"); string filename = "http://dev-rs/myClient/myClickOnce/myApp.config.xml"; Console.WriteLine(filename); XmlDocument doc = new XmlDocument(); doc.Load(filename); Console.WriteLine("Loaded"); Console.WriteLine("Inner Text : " + doc.InnerText); }

    Read the article

  • not able to Deserialize object

    - by Ravisha
    I am having following peice of code ,where in i am trying to serialize and deserailize object of StringResource class. Please note Resource1.stringXml = its coming from resource file.If i pass strelemet.outerXMl i get the object from Deserialize object ,but if i pass Resource1.stringXml i am getting following exception {"< STRING xmlns='' was not expected."} System.Exception {System.InvalidOperationException} class Program { static void Main(string[] args) { StringResource str = new StringResource(); str.DELETE = "CanDelete"; str.ID= "23342"; XmlElement strelemet = SerializeObjectToXmlNode (str); StringResource strResourceObject = DeSerializeXmlNodeToObject<StringResource>(Resource1.stringXml); Console.ReadLine(); } public static T DeSerializeXmlNodeToObject<T>(string objectNodeOuterXml) { try { TextReader objStringsTextReader = new StringReader(objectNodeOuterXml); XmlSerializer stringResourceSerializer = new XmlSerializer(typeof(T),string.Empty); return (T)stringResourceSerializer.Deserialize(objStringsTextReader); } catch (Exception excep) { return default(T); } } public static XmlElement SerializeObjectToXmlNode(object obj) { using (MemoryStream memoryStream = new MemoryStream()) { try { XmlSerializerNamespaces xmlNameSpace = new XmlSerializerNamespaces(); xmlNameSpace.Add(string.Empty, string.Empty); XmlWriterSettings writerSettings = new XmlWriterSettings(); writerSettings.CloseOutput = false; writerSettings.Encoding = System.Text.Encoding.UTF8; writerSettings.Indent = false; writerSettings.OmitXmlDeclaration = true; XmlWriter writer = XmlWriter.Create(memoryStream, writerSettings); XmlSerializer xmlserializer = new XmlSerializer(obj.GetType()); xmlserializer.Serialize(writer, obj, xmlNameSpace); writer.Close(); memoryStream.Position = 0; XmlDocument serializeObjectDoc = new XmlDocument(); serializeObjectDoc.Load(memoryStream); return serializeObjectDoc.DocumentElement; } catch (Exception excep) { return null; } } } } public class StringResource { [XmlAttribute] public string DELETE; [XmlAttribute] public string ID; }

    Read the article

  • Populate textboxes with XmlNode.Attributes

    - by Doug
    I have Data.xml: <?xml version="1.0" encoding="utf-8" ?> <data> <album> <slide title="Autum Leaves" description="Leaves from the fall of 1986" source="images/Autumn Leaves.jpg" thumbnail="images/Autumn Leaves_thumb.jpg" /> <slide title="Creek" description="Creek in Alaska" source="images/Creek.jpg" thumbnail="images/Creek_thumb.jpg" /> </album> </data> I'd like to be able to edit the attributes of each Slide node via GridView (that has a "Select" column added.) And so far I have: protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { int selectedIndex = GridView1.SelectedIndex; LoadXmlData(selectedIndex); } private void LoadXmlData(int selectedIndex) { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(MapPath(@"..\photo_gallery\Data.xml")); XmlNodeList nodelist = xmldoc.DocumentElement.ChildNodes; XmlNode xmlnode = nodelist.Item(selectedIndex); titleTextBox.Text = xmlnode.Attributes["title"].InnerText; descriptionTextBox.Text = xmlnode.Attributes["description"].InnerText; sourceTextBox.Text = xmlnode.Attributes["source"].InnerText; thumbTextBox.Text = xmlnode.Attributes["thumbnail"].InnerText; } The code for LoadXmlData is just a guess on my part - I'm new to working with xml in this way. I'd like have the user to slected the row from the gridview, then populate a set of text boxes with each slide attributed for updating back to the Data.xml file. The error I'm getting is Object reference not set to an instance of an object" at the line: titleTextBox.Text = xmlnode.Attributes["@title"].InnerText; so I'm not reaching the attribute "title" of the slide node. Thanks for any ideas you may have.

    Read the article

  • Getting "" at the beginning of my XML File after save()

    - by Remy
    I'm opening an existing XML file with c# and I replace some nodes in there. All works fine. Just after I save it, I get the following characters at the beginning of the file:  (EF BB BF in HEX) The whole first line: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> The rest of the file looks like a normal XML file. The simplified code is here: XmlDocument doc = new XmlDocument(); doc.Load(xmlSourceFile); XmlNode translation = doc.SelectSingleNode("//trans-unit[@id='127']"); translation.InnerText = "testing"; doc.Save(xmlTranslatedFile); I'm using a C# WinForm Application. With .NET 4.0. Any ideas? Why would it do that? Can we disable that somehow? It's for Adobe InCopy and it does not open it like this. UPDATE: Alternative Solution: Saving it with the XmlTextWriter works too: XmlTextWriter writer = new XmlTextWriter(inCopyFilename, null); doc.Save(writer);

    Read the article

  • populate textboxs with xml node attributes

    - by Doug
    I have Data.xml: <?xml version="1.0" encoding="utf-8" ?> <data> <album> <slide title="Autum Leaves" description="Leaves from the fall of 1986" source="images/Autumn Leaves.jpg" thumbnail="images/Autumn Leaves_thumb.jpg" /> <slide title="Creek" description="Creek in Alaska" source="images/Creek.jpg" thumbnail="images/Creek_thumb.jpg" /> </album> </data> I'd like to be able to edit the attributes of each Slide node via GridView (that has a "Select" column added.) And so far I have: protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { int selectedIndex = GridView1.SelectedIndex; LoadXmlData(selectedIndex); } private void LoadXmlData(int selectedIndex) { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(MapPath(@"..\photo_gallery\Data.xml")); XmlNodeList nodelist = xmldoc.DocumentElement.ChildNodes; XmlNode xmlnode = nodelist.Item(selectedIndex); titleTextBox.Text = xmlnode.Attributes["title"].InnerText; descriptionTextBox.Text = xmlnode.Attributes["description"].InnerText; sourceTextBox.Text = xmlnode.Attributes["source"].InnerText; thumbTextBox.Text = xmlnode.Attributes["thumbnail"].InnerText; The code for LoadXmlData is just a guess on my part - I'm new to working with xml in this way. I'd like have the user to slected the row from the gridview, then populate a set of text boxes with each slide attributed for updating back to the Data.xml file. The error I'm getting is "Object reference not set to an instance of an object" at the line: titleTextBox.Text = xmlnode.Attributes["@title"].InnerText; - so I'm not reaching the attribute "title" of the slide node. Thanks for any ideas you may have.

    Read the article

  • Pros/cons of reading connection string from physical file vs Application object (ASP.NET)?

    - by HaterTot
    my ASP.NET application reads an xml file to determine which environment it's currently in (e.g. local, development, production). It checks this file every single time it opens a connection to the database, in order to know which connection string to grab from the Application Settings. I'm entering a phase of development where efficiency is becoming a concern. I don't think it's a good idea to have to read a file on a physical disk ever single time I wish to access the database (very often). I was considering storing the connection string in Application["ConnectionString"]. So the code would be public static string GetConnectionString { if (Application["ConnectionString"] == null) { XmlDocument doc = new XmlDocument(); doc.Load(HttpContext.Current.Request.PhysicalApplicationPath + "bin/ServerEnvironment.xml"); XmlElement xe = (XmlElement) xnl[0]; switch (xe.InnerText.ToString().ToLower()) { case "local": connString = Settings.Default.ConnectionStringLocal; break; case "development": connString = Settings.Default.ConnectionStringDevelopment; break; case "production": connString = Settings.Default.ConnectionStringProduction; break; default: throw new Exception("no connection string defined"); } Application["ConnectionString"] = connString; } return Application["ConnectionString"].ToString(); } I didn't design the application so I figure there must have been a reason for reading the xml file every time (to change settings while the application runs?) I have very little concept of the inner workings here. What are the pros and cons? Do you think I'd see a small performance gain by implementing the function above? THANKS

    Read the article

  • When NOT TO USE 'this' keyword?

    - by LifeH2O
    Sorry for asking it again, there are already 3 questions about this keyword. But all of them tell the purpose of 'this'. My question is when not to use 'this' keyword . OR Is it all right to use this keyword always in situation like the code class RssReader { private XmlTextReader _rssReader; private XmlDocument _rssDoc; private XmlNodeList _xn; protected XmlNodeList Item { get { return _xn; } } public int Count { get { return _count; } } public bool FetchFeed(String url) { this._rssReader = new XmlTextReader(url); this._rssDoc = new XmlDocument(); _rssDoc.Load(_rssReader); _xn = _rssDoc.SelectNodes("/rss/channel/item"); _count = _xn.Count; return true; } } here i have not used 'this' with "_xn" and "_count" also not with "_rssDoc.Load(_rssReader);" is it fine? Should i use "this" with all occurrences of class variables within the class?

    Read the article

  • Counting elements and reading attributes with .net2.0 ?

    - by Prix
    I have an application that is on .net 2.0 and I am having some difficult with it as I am more use to linq. The xml file look like this: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <updates> <files> <file url="files/filename.ext" checksum="06B9EEA618EEFF53D0E9B97C33C4D3DE3492E086" folder="bin" system="0" size="40448" /> <file url="files/filename.ext" checksum="CA8078D1FDCBD589D3769D293014154B8854D6A9" folder="" system="0" size="216" /> <file url="files/filename.ext" checksum="CA8078D1FDCBD589D3769D293014154B8854D6A9" folder="" system="0" size="216" /> </files> </updates> The file is downloaded and readed on the fly: XmlDocument readXML = new XmlDocument(); readXML.LoadXml(xmlData); Initially i was thinking it would go with something like this: XmlElement root = doc.DocumentElement; XmlNodeList nodes = root.SelectNodes("//files"); foreach (XmlNode node in nodes) { ... im reading it ... } But before reading them I need to know how many they are to use on my progress bar and I am also clueless on how to grab the attribute of the file element in this case. How could I count how many "file" ELEMENTS I have (count them before entering the foreach ofc) and read their attributes ? I need the count because it will be used to update the progress bar. Overall it is not reading my xml very well.

    Read the article

  • Modify XML existing content in C#

    - by Nano HE
    Purpose: I plan to Create a XML file with XmlTextWriter and Modify/Update some Existing Content with XmlNode SelectSingleNode(), node.ChildNode[?].InnerText = someting, etc. After I created the XML file with XmlTextWriter as below. XmlTextWriter textWriter = new XmlTextWriter("D:\\learning\\cs\\myTest.xml", System.Text.Encoding.UTF8); I practiced the code below. But failed to save my XML file. XmlDocument doc = new XmlDocument(); doc.Load("D:\\learning\\cs\\myTest.xml"); XmlNode root = doc.DocumentElement; XmlNode myNode; myNode= root.SelectSingleNode("descendant::books"); .... textWriter.Close(); doc.Save("D:\\learning\\cs\\myTest.xml"); I found it is not good to produce like my way. Is there any suggestion about it? I am not clear about the concepts and usage of both XmlTextWriter and XmlNode in the same project. Thank you for reading and replies.

    Read the article

  • Parsing XML in C# from stream

    - by Phillip
    I've tried several methods, from Linq to loading the data to an XML document, but i can't seem to be able to return the result that i need. here's the example XML: <serv:message xmlns:serv="http://www.webex.com/schemas/2002/06/service" xmlns:com="http://www.webex.com/schemas/2002/06/common" xmlns:event="http://www.webex.com/schemas/2002/06/service/event"><serv:header><serv:response><serv:result>SUCCESS</serv:result><serv:gsbStatus>PRIMARY</serv:gsbStatus></serv:response></serv:header><serv:body><serv:bodyContent xsi:type="event:createEventResponse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><event:sessionKey>11111111</event:sessionKey><event:guestToken>111111111111111111111</event:guestToken></serv:bodyContent></serv:body></serv:message> And, here's what i've tried to do: StreamReader reader = new StreamReader(dataStream); XmlDocument doc = new XmlDocument(); doc.LoadXml(reader.ReadToEnd()); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); XmlNamespaceManager ns2 = new XmlNamespaceManager(doc.NameTable); XmlNamespaceManager ns3 = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("serv", "http://www.webex.com/schemas/2002/06/service"); ns2.AddNamespace("com", "http://www.webex.com/schemas/2002/06/common"); ns3.AddNamespace("event", "http://www.webex.com/schemas/2002/06/service/event"); XmlNode node = doc.SelectSingleNode("result",ns); Yet, for some reason i cannot ever seem to return the actual result, which should be either 'SUCCESS' or 'FAILURE' based on the actual xml above. How can i do this?

    Read the article

  • Object reference not set to an instance of an object.

    - by Lambo
    I have the following code - private static void convert() { string csv = File.ReadAllText("test.csv"); string year = "2008"; XDocument doc = ConvertCsvToXML(csv, new[] { "," }); doc.Save("update.xml"); XmlTextReader reader = new XmlTextReader("update.xml"); XmlDocument testDoc = new XmlDocument(); testDoc.Load(@"update.xml"); XDocument turnip = XDocument.Load("update.xml"); webservice.singleSummary[] test = new webservice.singleSummary[1]; webservice.FinanceFeed CallWebService = new webservice.FinanceFeed(); foreach(XElement el in turnip.Descendants("row")) { test[0].account = el.Descendants("var").Where(x => (string)x.Attribute("name") == "account").SingleOrDefault().Attribute("value").Value; test[0].actual = System.Convert.ToInt32(el.Descendants("var").Where(x => (string)x.Attribute("name") == "actual").SingleOrDefault().Attribute("value").Value); test[0].commitment = System.Convert.ToInt32(el.Descendants("var").Where(x => (string)x.Attribute("name") == "commitment").SingleOrDefault().Attribute("value").Value); test[0].costCentre = el.Descendants("var").Where(x => (string)x.Attribute("name") == "costCentre").SingleOrDefault().Attribute("value").Value; test[0].internalCostCentre = el.Descendants("var").Where(x => (string)x.Attribute("name") == "internalCostCentre").SingleOrDefault().Attribute("value").Value; MessageBox.Show(test[0].account, "Account"); MessageBox.Show(System.Convert.ToString(test[0].actual), "Actual"); MessageBox.Show(System.Convert.ToString(test[0].commitment), "Commitment"); MessageBox.Show(test[0].costCentre, "Cost Centre"); MessageBox.Show(test[0].internalCostCentre, "Internal Cost Centre"); CallWebService.updateFeedStatus(test, year); } It is coming up with the error of - NullReferenceException was unhandled, saying that the object reference not set to an instance of an object. The error occurs on the first line test[0].account. How can I get past this?

    Read the article

  • deleting entire xml node with datagrid

    - by DuranL
    Hello, I have the following xml structure: <systemtest> <test id="0"> <name>Test One</name> </test> <test id="1"> <name>Test Two</name> </test> </systemtest> The name gets displayed in the 1ste colum of the datagrid, where in the 2nd colum there is a buttoncolumn with delete button. How exactly can i use xpath and navigate to the current node lets say with test id="0" and delete it (including name)? Its unclear how i can say to this method what row he has to delete exactly. XmlDocument XMLDoc = new XmlDocument(); XMLDoc.Load(XMLFile); XPathNavigator nav = XMLDoc.CreateNavigator(); nav.SelectSingleNode("...."); //?? nav.DeleteSelf(); //will this do the trick? Also the id gets generated in a seperate class where the above method should be. Thanks in advance.

    Read the article

  • xsl transform: problem with Ampersand URL parameters

    - by Rac123
    I'm having issues with transforming XSL with parameters in a URL. I'm at a point that I can't change the C# code anymore, only can make changes to xsl file. C# code: string xml = "<APPLDATA><APPID>1052391</APPID></APPLDATA>"; XmlDocument oXml = new XmlDocument(); oXml.LoadXml(xml); XslTransform oXslTransform = new XslTransform(); oXslTransform.Load(@"C:\Projects\Win\ConsoleApps\XslTransformTest\S15033.xsl"); StringWriter oOutput = new StringWriter(); oXslTransform.Transform(oXml, null, oOutput) XSL Code: <body> <xsl:variable name="app"> <xsl:value-of select="normalize-space(APPLDATA/APPID)" /> </xsl:variable> <div id="homeImage" > <xsl:attribute name="style"> background-image:url("https://server/image.gif?a=10&amp;Id='<xsl:value-of disable-output-escaping="yes" select="$app" />'") </xsl:attribute> </div> </body> </html> URL transformed: https://server/image.gif?a=10&Id='1052391' URL Expected: https://server/image.gif?a=10&Id='1052391' How do I fix this? The output (oOutput.ToString()) is being used in an email template so it's taking the URL transformed literally. When you click on this request (with the correct server name of course), the 403 (Access forbidden) error is being thrown.

    Read the article

  • avoid extra xmlns:xsi while adding a attribute to xml root element in C#.net

    - by Rakesh kumar
    Please help me. First pls forgive me if i am wrong. i am createing a xmlfile using c#.net . my Code is like XmlDocument d = new XmlDocument(); XmlDeclaration xmlDeclaration = d.CreateXmlDeclaration("1.0", "utf-8", null); d.InsertBefore(xmlDeclaration,d.DocumentElement); XmlElement root = d.CreateElement("ITRETURN","ITR","http://incometaxindiaefiling.gov.in/ITR1"); XmlAttribute xsiNs = d.CreateAttribute("xsi:schemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); xsiNs.Value = "http://incometaxindiaefiling.gov.in/main ITRMain10.xsd"; root.SetAttributeNode(xsiNs); //root.SetAttribute("xsi:schemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); root.SetAttribute("xmlns:ITR1FORM", "http://incometaxindiaefiling.gov.in/ITR1"); root.SetAttribute("xmlns:ITR2FORM", "http://incometaxindiaefiling.gov.in/ITR2"); root.SetAttribute("xmlns:ITR3FORM", "http://incometaxindiaefiling.gov.in/ITR3"); root.SetAttribute("xmlns:ITR4FORM", "http://incometaxindiaefiling.gov.in/ITR4"); d.AppendChild(root); d.Save("c://myxml.xml"); and i am getting output like this - - root node But My requirement is like + any value please help

    Read the article

  • Should I thread this?

    - by Psytronic
    I've got a "Loading Progress" WPF form which I instantiate when I start loading some results into my Main Window, and every time a result is loaded I want the progress bar to fill up by x amount (Based on the amount of results I'm loading). However what happens is that the Progress bar in the window stays blank the entire time, until the results have finished loading, then it will just display the full progress bar. Does this need threading to work properly? Or is it just to do with the way I'm trying to get it to work? //code snippet LoadingProgress lp = new LoadingProgress(feedCount); lp.Show(); foreach (FeedConfigGroup feed in _Feeds) { feed.insertFeeds(lp); } //part of insertFeeds(LoadingProgress lbBox) foreach (Feeds fd in _FeedSource) { lpBox.setText(fd.getName); XmlDocument feedResults = new XmlDocument(); feedResults.PreserveWhitespace = false; try { feedResults.Load(wc.OpenRead(fd.getURL)); } catch (WebException) { lpBox.addError(fd.getName); } foreach (XmlNode item in feedResults.SelectNodes("/rss/channel/item")) { //code for processing the nodes... } lpBox.progressIncrease(); } If more code is needed let me know.

    Read the article

  • How to compare dictonary key with xml attribute value in xml using LINQ in c #?

    - by Pramodh
    Dear all, i've a dictonary " dictSample " which contains 1 data1 2 data2 3 data3 4 data4 and an xml file"sample.xml" in the form of: <node> <element id="1" value="val1"/> <element id="2" value="val2"/> <element id="3" value="val3"/> <element id="4" value="val4"/> <element id="5" value="val5"/> <element id="6" value="val6"/> <element id="7" value="val7"/> </node> i need to match the dictonary keys with the xml attribute id and to insert the matching id and the value of attribute"value" into another dictonary now i'm using like: XmlDocument XDOC = new XmlDocument(); XDOC.Load("Sample.xml"); XmlNodeList NodeList = XDOC.SelectNodes("//element"); Dictionary<string, string> dictTwo = new Dictionary<string, string>(); foreach (string l_strIndex in dictSample .Keys) { foreach (XmlNode XNode in NodeList) { XmlElement XEle = (XmlElement)XNode; if (dictSample[l_strIndex] == XEle.GetAttribute("id")) dictTwo.Add(dictSample[l_strIndex], XEle.GetAttribute("value").ToString()); } } please help me to do this in a simple way using LINQ

    Read the article

  • how to determine count of tag

    - by peter
    I have a bit of xml file named Sample.xml which is shown below <?xml version="1.0" encoding="ISO-8859-1"?> <countries> <country> <text>Norway</text> <value>N</value> </country> <country> <text>Sweden</text> <value>S</value> </country> <country> <text>France</text> <value>F</value> </country> <country> <text>Italy</text> <value>I</value> </country> </countries> i have button named submit(button1).If i click that button i need to display the count(PartitionName="AIX") in a text box named textBox1, means How many PartitionName="AIX" is belonging to Type="NIC" Can any one give me the c# code I did like this,,but not able to get the answaer private void button1_Click(object sender, EventArgs e) { XmlDocument doc1 = new XmlDocument(); doc1.Load(@"D:\New Folder\WindowsFormsApplication3\WindowsFormsApplication3\Sample.xml"); XmlNodeList a = doc1.GetElementsByTagName("AIX"); textBox1.Text = a.Count.ToString(); }

    Read the article

  • Namespace Traversal

    - by RikSaunderson
    I am trying to parse the following sample piece of XML: <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soapenv:Body> <d2LogicalModel modelBaseVersion="1.0" xmlns="http://datex2.eu/schema/1_0/1_0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://datex2.eu/schema/1_0/1_0 http://datex2.eu/schema/1_0/1_0/DATEXIISchema_1_0_1_0.xsd"> <payloadPublication xsi:type="PredefinedLocationsPublication" lang="en"> <predefinedLocationSet id="GUID-NTCC-VariableMessageSignLocations"> <predefinedLocation id="VMS30082775"> <predefinedLocationName> <value lang="en">VMS M60/9084B</value> </predefinedLocationName> </predefinedLocation> </predefinedLocationSet> </payloadPublication> </d2LogicalModel> </soapenv:Body> </soapenv:Envelope> I specifically need to get at the contents of the top-level predefinedLocation tag. By my calculations, the correct XPath should be /soapenv:Envelope/soapenv:Body/d2LogicalModel/payloadPublication/predefinedLocationSet/predefinedLocation I am using the following C# code to parse the XML: string filename = "content-sample.xml"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filename); XmlNamespaceManager nsmanager = new XmlNamespaceManager(xmlDoc.NameTable); nsmanager.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/Envelope"); string xpath ="/soapenv:Envelope/soapenv:Body/d2LogicalModel/payloadPublication/predefinedLocationSet/predefinedLocation"; XmlNodeList itemNodes = xmlDoc.SelectNodes(xpath, nsmanager); However, this keeps coming up with no results. Can anyone shed any light on this, because I feel like I'm banging my head on a brick wall.

    Read the article

  • C# XML node with colon

    - by Sticky
    Hi, my code attempts to grab data from the RSS feed of a website. It grabs the nodes fine, but when attempting to grab the data from a node with a colon, it crashes and gives the error "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function." The code is shown below: WebRequest request = WebRequest.Create("http://buypoe.com/external.php?type=RSS2&lastpost=true"); WebResponse response = request.GetResponse(); StringBuilder sb = new StringBuilder(""); System.IO.StreamReader rssStream = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8")); XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssStream); XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); for (int i = 0; i < 5; i++) { XmlNode rssDetail; rssDetail = rssItems.Item(i).SelectSingleNode("dc:creator"); if (rssDetail != null) { user = rssDetail.InnerText; } else { user = ""; } } I understand that I need to define the namespace, but am unsure how to do this. Help would be appreciated.

    Read the article

  • Reading the .vcproj file with C#

    - by Dulantha Fernando
    We create the vcproj file with the makefileproj keyword so we can use our own build in VS. My question is, using C#, how do you read the "C++" from the following vcproj file: <?xml version="1.0" encoding="Windows-1252"?> <VisualStudioProject ProjectType="Visual C++" Version="8.00" Name="TestCSProj" ProjectGUID="{840501C9-6AFE-8CD6-1146-84208624C0B0}" RootNamespace="TestCSProj" Keyword="MakeFileProj" > <Platforms> <Platform Name="x64" /> <Platform Name="C++" ===> I need to read "C++" /> </Platforms> I used XmlNode and got upto the second Platform: String path = "C:\\blah\\TestCSProj\\TestCSProj\\TestCSProj.vcproj"; FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(fs); XmlNodeList oldFiles = xmldoc.GetElementsByTagName("Platform"); XmlAttribute name = oldFiles[1].Attributes[0]; Console.WriteLine(name.Name); This will print Name, but I need "C++". How do I read that? Thank you very much in advance

    Read the article

  • How to find an XPath query to Element/Element without namespaces (XmlSerializer, fragment)?

    - by Veksi
    Assume this simple XML fragment in which there may or may not be the xml declaration and has exactly one NodeElement as a root node, followed by exactly one other NodeElement, which may contain an assortment of various number of different kinds of elements. <?xml version="1.0"> <NodeElement xmlns="xyz"> <NodeElement xmlns=""> <SomeElement></SomeElement> </NodeElement> </NodeElement> How could I go about selecting the inner NodeElement and its contents without the namespace? For instance, "//*[local-name()='NodeElement/NodeElement[1]']" (and other variations I've tried) doesn't seem to yield results. As for in general the thing that I'm really trying to accomplish is to Deserialize a fragment of a larger XML document contained in a XmlDocument. Something like the following var doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(@"trickynodefile.xml")); //ReadAllText to avoid Unicode trouble. var n = doc.SelectSingleNode("//*[local-name()='NodeElement/NodeElement[1]']"); using(var reader = XmlReader.Create(new StringReader(n.OuterXml))) { var obj = new XmlSerializer(typeof(NodeElementNodeElement)).Deserialize(reader); I believe I'm missing just the right XPath expression, which seem to be rather elusive. Any help much appreciated!

    Read the article

  • Android - Parsing XML with XPath

    - by Ruben Deig Ramos
    First of all, thanks to all the people who's going to spend a little time on this question. Second, sorry for my english (not my first language! :D). Well, here is my problem. I'm learning Android and I'm making an app which uses a XML file to store some info. I have no problem creating the file, but trying to read de XML tags with XPath (DOM, XMLPullParser, etc. only gave me problems) I've been able to read, at least, the first one. Let's see the code. Here is the XML file the app generates: <dispositivo> <id>111</id> <nombre>Name</nombre> <intervalo>300</intervalo> </dispositivo> And here is the function which reads the XML file: private void leerXML() { try { XPathFactory factory=XPathFactory.newInstance(); XPath xPath=factory.newXPath(); // Introducimos XML en memoria File xmlDocument = new File("/data/data/com.example.gps/files/devloc_cfg.xml"); InputSource inputSource = new InputSource(new FileInputStream(xmlDocument)); // Definimos expresiones para encontrar valor. XPathExpression tag_id = xPath.compile("/dispositivo/id"); String valor_id = tag_id.evaluate(inputSource); id=valor_id; XPathExpression tag_nombre = xPath.compile("/dispositivo/nombre"); String valor_nombre = tag_nombre.evaluate(inputSource); nombre=valor_nombre; } catch (Exception e) { e.printStackTrace(); } } The app gets correctly the id value and shows it on the screen ("id" and "nombre" variables are assigned to a TextView each one), but the "nombre" is not working. What should I change? :) Thanks for all your time and help. This site is quite helpful! PD: I've been searching for a response on the whole site but didn't found any.

    Read the article

  • Uploading an xml direct to ftp

    - by Joshua Maerten
    i put this direct below a button: XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("Login"); XmlElement id = doc.CreateElement("id"); id.SetAttribute("userName", usernameTxb.Text); id.SetAttribute("passWord", passwordTxb.Text); XmlElement name = doc.CreateElement("Name"); name.InnerText = nameTxb.Text; XmlElement age = doc.CreateElement("Age"); age.InnerText = ageTxb.Text; XmlElement Country = doc.CreateElement("Country"); Country.InnerText = countryTxb.Text; id.AppendChild(name); id.AppendChild(age); id.AppendChild(Country); root.AppendChild(id); doc.AppendChild(root); // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://users.skynet.be"); request.Method = WebRequestMethods.Ftp.UploadFile; request.UsePassive = false; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("fa490002", "password"); // Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader(); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); response.Close(); MessageBox.Show("Created SuccesFully!"); this.Close(); but i always get an error of the streamreader path, what do i need to place there ? the meening is, creating an account and when i press the button, an xml file is saved to, ftp://users.skynet.be/testxml/ the filename is from usernameTxb.Text + ".xml".

    Read the article

  • How can I write to a single xml file from two programs at the same time?

    - by Tom Bushell
    We recently started working with XML files, after many years of experience with the old INI files. My coworker found some CodeProject sample code that uses System.Xml.XmlDocument.Save. We are getting exceptions when two programs try to write to the same file at the same time. System.IO.IOException: The process cannot access the file 'C:\Test.xml' because it is being used by another process. This seems obvious in hindsight, but we had not anticipated it because accessing INI files via the Win32 API does not have this limitation. I assume there's some arbitration done by the Win32 calls that work at a higher level than the the XmlDocument.Save method. I'm hoping there are higher level XML routines somewhere in the .Net library that work similarily to the Win32 functions, but don't know where to start looking. Or maybe we can set up our file access permissions to allow multiple programs to write to the same file? Time is short (like almost all SW projects), and if we can't find a solution quickly, we'll have to hold our noses and go back to INI files.

    Read the article

  • Subitems are not all added to a list view in C# using XmlNodeList

    - by tim
    I'm working on extracting data from an RSS feed. In my listview (rowNews), I've got two columns: Title and URL. When the button is clicked, all of the titles of the articles are showing up in the title column, but only one URL is added to the URL column. I switched them around so that the URLs would be added to the first column and all of the correct URLs appeared... leading me to think this is a problem with my listview source (it's my first time working with subitems). Here's the original, before I started experimenting with the order: private void button1_Click(object sender, EventArgs e) { XmlTextReader rssReader = new XmlTextReader(txtUrl.Text); XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssReader); XmlNodeList titleList = rssDoc.GetElementsByTagName("title"); XmlNodeList urlList = rssDoc.GetElementsByTagName("link"); ListViewItem lvi = new ListViewItem(); for (int i = 0; i < titleList.Count; i++) { rowNews.Items.Add(titleList[i].InnerXml); } for (int i = 0; i < urlList.Count; i++) { lvi.SubItems.Add(urlList[i].InnerXml); } rowNews.Items.Add(lvi); }

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13  | Next Page >