.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

XMLDocument, problem reading Node.

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net



I am doing the following:


System.Net.WebRequest myRequest = System.Net.WebRequest.Create("http://www.atlantawithkid.com/feed/"); 
System.Net.WebResponse myResponse = myRequest.GetResponse(); 
System.IO.Stream rssStream = myResponse.GetResponseStream(); 
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument(); 
System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); 
System.Xml.XmlNode rssDetail; 
string sRssDescription;  
rssDetail = rssItems.Item(0).SelectSingleNode("description"); 
if (rssDetail != null) 
    sRssDescription = rssDetail.InnerText; 

However, when I read the "description" node and view the InnerText, or the InnerXML, the string is different than in the original XML document.

The string returned has and ellipses and the data is truncated. However, in the original XML document there is data that I can see.

Is there a way to select this node without the data being altered?

The original XML <description> node is as follows:

			<description xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="html">
				<div class="tweetmeme_button" style="float:right;margin-le

View Complete Post

More Related Resource Links

reading excel file problem



i have 200 rows in my excel file. im using OleDbConnection to read the excel file.

The problem is that it will read all the blank rows from row 200 onwards. Is there a configuration im missing ? or is there a way to import all rows that has data? Here's some of my code.

string excelConnectionString =
               "Provider=Microsoft.Jet.OLEDB.4.0;" +
                "Data Source=" + filePath + ";" +
                "Extended Properties=Excel 8.0";

OleDbConnection excelConnection =
                    new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=NO'");

OleDbCommand cmd = new OleDbCommand("Select * from [list$]",excelConnection);

Problem when using Activator.CreateObject and reading App.Config file

Hello, this is the scenario. I have an application that load at runtime severals dll. these dll are actually "adapters" that wraps calls to web services, database and so on. The app.config of the "main" application stores in config sections all information necessary to each adapter (i.e.Web ServiceURL..) and I have created inside each adapter a class to ready those values the loading at run time the DLL has been implemented by storing all necessary types into a dictionary of generics and when I need to instanciate it I call the Activate.CreateObject and I pass the specific type (I means the name of the Adapter class) The problem is that the adapter class itself is not able to get the config value because ConfigSection has not been initialized. If I write: IInterfaceAdap adapt = new myAdapter() -> I read the config data IInterfaceAdap adapt = (IInterfaceAdap)Activator.CreateObject (type) -> now way to read the data stored in the App.Config. I think that I undertood the problem but I'm not able to find a workaround to read data store in the app.config!! I need help please!!  

Problem reading my DLL

Hi there, I have a problem trying to display my DLL on Visual Studio 2005. I created a windows control library and I want to access it from my asp/c# website. I use the following code to display it: <object id="myComponent" classid="http:WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1" height="300px" width="100%" />However, when I run the website it just shows me a plain box. With nothing in it.Another thing, the VIEWASTEXT inserted in the object it gets underlined and when I roll the mouse over it says:"VIEWASTEXT attribute is not valid attribute of element 'object'"Can anyone help me go around this problem or fix it?Thank you in advance ;)

Problem reading from cookie

I'm trying to build a smaller shop and I have run into some problems with cookies. This is my code in the shoppingcartaccess classprivate static string shoppingCartId { get { // get the current HttpContext HttpContext context = HttpContext.Current; // try to retrieve the cart ID from the user cookie string cartId = context.Request.Cookies["CartID"].Value; // HERE I GET THE ERROR // if the cart ID isn't in the cookie... // check if the cart ID exists as a cookie if (context.Request.Cookies["CartID"] != null) { // return the id return cartId; } else // if the cart ID doesn't exist in the cookie as well, generate // a new ID { // generate a new GUID cartId = Guid.NewGuid().ToString(); // create the cookie object and set its value HttpCookie cookie = new HttpCookie("CartID", cartId); // set the cookie's expiration date int howManyDays = SiteConfig.CartPersistDays; DateTime currentDate = DateTime.Now; TimeSpan timeSpan = new TimeSpan(howManyDays, 0, 0, 0); DateTime expirationDate = currentDate.Add(timeSpan); c

add an XML node to an existing XMLdocument

I want to add an XML node (locationNode) to an existing XMLdocument (xmldoc)However, I get the error: The node to be inserted is from a different document context.Which makes sense, but then I dont know how I can do what I want.Here's my code:Dim doc As XmlDocument = New XmlDocument()Dim locationNode As XmlNode = doc.CreateElement("location")Dim locationAttribute As XmlAttribute = doc.CreateAttribute("id")locationAttribute.Value = "3"locationNode.Attributes.Append(locationAttribute)'doc.AppendChild(locationNode)Dim titleNode As XmlNode = doc.CreateElement("title")titleNode.AppendChild(doc.CreateTextNode("Opera house"))locationNode.AppendChild(titleNode)xmldoc.AppendChild(locationNode)contents of xmldoc:    <root>    <data>        <compare>            <locations>                <location id="4">                    <title>Empire state building</title>                </location>                <location id=&quo

DB Reading problem

I was having problem with my database, I couldn't see any of the table in the enterprise manager. when I execute any sql in some of the tables of the database it was giving error msf that "Bad Page Id". I went through the FAQs and Forums, I tried with this queries. ALTER DATABASE DMS_PILOT SET SINGLE_USER go DBCC CHECKDB (DMS_PILOT, REPAIR_ALLOW_DATA_LOSS) GO When I execute this query I found some new error messeges mentioned as below. "Server: Msg 8966, Level 16, State 1, Line 2 Could not read and latch page (1:3168) with latch type SH. sysindexes failed. DBCC execution completed. If DBCC printed error messages, contact your system administrator." Please help me.

DB Reading problem

I was having problem with my database, I couldn't see any of the table in the enterprise manager. when I execute any sql in some of the tables of the database it was giving error msf that "Bad Page Id". I went through the FAQs and Forums, I tried with this queries. ALTER DATABASE DMS_PILOT SET SINGLE_USER go DBCC CHECKDB (DMS_PILOT, REPAIR_ALLOW_DATA_LOSS) GO When I execute this query I found some new error messeges mentioned as below. "Server: Msg 8966, Level 16, State 1, Line 2 Could not read and latch page (1:3168) with latch type SH. sysindexes failed. DBCC execution completed. If DBCC printed error messages, contact your system administrator." Please help me.

problem reading from app.config


I have added an app.config file in my winform aplicaion an added one key

<add key="IsFirstRun" value="True" />

then I am tying to read it like this:


but I am getting this error:

Configuration system failed to initialize

on the MessageBox line..

why? how ca I fix please?

Jassim Rahma

Replace node contents using xmldocument




Attempting to replace the contents of a node, but not having much luck..

I need to look at my Keywords node, if it has the word 'test,' in it then replace it with ""

Essentially I'm trying to delete one of the keywords - they will always have a comma after each word as well.

So I'm trying to say in code: For any elements that is in the department Claims, get the Keywords & if it contains the string 'test,' replace it with nothing.


My elements look like this:

    <Link Type="Page" Target=""><![CDATA[]]></Link>

..additional elements just like this one..


My code like this:


How to get node using XMLDocument and update value



This is my XML.

<xml version="1.0" encoding="utf-16">
    <x> test value 1 </x>
    <y> test value 2</y>

        <x> test value 3</x>
        <y> test value 4</y>

                <x> test value 5</x>
                <y> test value 6 </y>




The actual XML is a deep hierarchy same way above that has so may <objA> and <objB>.

Please remember, I have to use XMLDocument only, not XDocument.

Now, I have to find a particular <objA> where <x> = "test value 5" and update its <y> to "some new value".

and then save that whole XMLDocument so that it is updated.

Can someone please tell me how can I achieve this using XMLDocument?


Thanks in advance,


XElement to XMLDocument problem


Im usintg LINQ to return some xml from a database, I then need to convert the XElement to an XMLDocument, Ive used this code

XmlDocument xmlDoc = new XmlDocument();

XML is the XElement from a LINQ query, but I get an exception

'Root element is missing'

this is the xml returned from the LINQ query that Im trying to put into an XMLDocument , can anyone see what the problem is ?

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Process xmlns="http://address here">

Reading inner node values of xml


I have an xml file in the below format.

<?xml version="1.0" encoding="utf-8"?>
<Control ID="Title" Editable="true" UserControlName="Title.ascx"  Visible="true" Enabled="true" ></Control>
<Control ID="Edit"  Editable="true" UserControlName="Edit.ascx"  Visible="true" Enabled="true"></Control>

I need to loop through each element and get the value.

Using XmlTextReader iam able to do that but  If the tag name is <Control> then i need to get values for ID,Editable,UserControlName,Visible etc.. after that again read node values only  if the node is <Content> it should read all the attribute values for  that <Content>.

Please help me out

StreamReader.BaseStream.Read() problem in Random access reading of file


I am trying to randomly access a file but not fully understanding this class.

I have

 // Seek to the beginning of the field

System.IO.StreamReader srFile = new System.IO.StreamReader(_FileName.PathAndFileName);

srFile.BaseStream.Seek(FieldOffset, SeekOrigin.Begin);

// Read the field

int FieldLength = Field.FieldLength;  

int BUFFER_SIZE = (int)RecordLength;

byte[] bBuffer = new Byte[BUFFER_SIZE];

srFile.BaseStream.Read(bBuffer, 0, (int)FieldLength);

string FieldValue;
FieldValue = bBuffer.ToString();

but bBuffer is numbers like:

[0] 32

and the value of FieldValue is "System.Byte[]"

I'm trying to get text as this is a text file.


Determine node type selected in TreeView and reading property values


I am hoping that someone can help me get past some problems I am having when using the WPF TreeView control.  I have a TreeView that at most can have 3 levels.  The levels are defined as Project, Discipline, Person which would look like the following:

+ Project

    + Discipline

        - Person

My TreeView is bound to a database using two HierarchicalDataTemplate's and then one DataTemplate (the binding is done in the XAML).

What I would like to get is the following information when selecting an item:

  1. Read the selected value (text of the selected node)
  2. Problem in reading WCF configuration settings



    The great thing about WCF is that you can configure you're WCF bindings in a configuration file and not through code.
    We are now making connection to WCF's webservices in our SharePoint code, but now the question is where to place the WCF configuration settings. 


    For deployment reasons we don't want to place the settings in the SharePoint web.config:

    -  can't be easily changed by admin users through SharePoint Gui

    -  new deployment needed to change configuration settings

    -  webservices u

SSIS 2008: Problem reading dynamic file during execution



I have a SSIS 2008 project that reads a bunch of files from a file (always the same file) from Machine A.
My package is running on Machine B and this is where the information is being imported to, my Reporting DB (sql 2008) is also located in Machine B. 
I have a dynamic log file that stores the execution errors every time the package is executed and its name is made up of the timestamp of when package starts executing. The "DelayValidation" option for this connection is set to "TRUE". When i execute my Package from Visual Studio 2008, it runs without a problem.
The problem is when i deploy my package into SQL Server 2008 and try running it through DTEXEC. I always get the following error:


Error: 2010-11-03 14:57:29.06
   Code: 0xC001401E
   Source: MyImportPackage Connection manager "ImportLog"
   Description: The file name "\\ip-address\d$\Logs\ImportManager\20101103_145726.txt" specified in the connection was not valid.

Problem while reading a Facebook RSS feed using SyndicationFeed


I am trying to read a Facebook RSS feed using the SyndicationFeed class. I have tried to do the following:
string url = "http://www.facebook.com/feeds/page.php?format=atom10&id=147782351928125";
XmlReader xmlReader = XmlReader.Create(url);

SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
foreach (SyndicationItem item in feed.Items)

But the load method throws this exception:
For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method.

I have also tried to add a XmlReaderSettings as suggested, but it just throws different errors. Any ideas?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend