C# - Get An XML Attribute With XmlReader.Create?
Aug 21, 2010
I am using XmlReader.Create to retrieve data from an RSS xml file. Then I am putting this data into a DataSet and binding it to a ListView:
XmlReader xmlReader = XmlReader.Create(this.RssUrl);
XmlDataDocument xdoc = new XmlDataDocument();
xdoc.DataSet.ReadXml(xmlReader, XmlReadMode.InferSchema);
The problem is that one of the fields I am trying to get is in an attribute. How do I get the "url" attribute from "media:thumbnail" below?
<item>
<title>Some Title</title>
<description>Content goes here...</description>
<link>http://www.mydomain.com?id=439</link>
<guid>453252362</guid>
<pubDate>Sat, 21 Aug 2010 11:00:00 GMT</pubDate>
<media:thumbnail url="http://www.mydomain.com/catalog/1111tn.jpg" />
<media:content url="http://www.mydomain.com/catalog/1111.jpg" />
</item>
I am bind it like this, but the media:thumbnail is null obviously because I need to get the attribute some how:
void singleItem_DataBinding(object sender, System.EventArgs e)
{
Label singleItem = (Label)sender;
singleItem.Text = String.Format(@"
<div class=""rlvI content"">
<div class=""image"">
<a href=""{0}""><img src=""{1}"" alt=""{2}""></a>
</div>
<p>
span class=""title"">{2}</span><br />
{3}
</p>
</div>",
((singleItem.NamingContainer as RadListViewDataItem).DataItem as DataRowView)["link"],
((singleItem.NamingContainer as RadListViewDataItem).DataItem as DataRowView)["media:thumbnail"],
((singleItem.NamingContainer as RadListViewDataItem).DataItem as DataRowView)["title"],
((singleItem.NamingContainer as RadListViewDataItem).DataItem as DataRowView)["description"]);
}
View 1 Replies
Similar Messages:
Aug 23, 2010
Sometimes I am getting a time out exception when reading an XML via a URL. Is there something I can do to prevent this, or is this a problem with the remote server? Below is my simple code:
XmlDocument doc = new XmlDocument();
doc.Load(XmlReader.Create(this.RssUrl));
I do not know how to pass that setting into the code above (or if that is even the correct solution): [URL]
Exception Details: System.Net.WebException: The operation has timed out
Stack Trace:
[WebException: The operation has timed out]
System.Net.HttpWebRequest.GetResponse() +5375213
System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) +69
System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +3929371
System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +54
System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext) +144
System.Xml.XmlReader.Create(String inputUri) +8
View 1 Replies
Mar 23, 2010
when i am executing xmlreader in enterprise library 4.1, iam getting an error like below
error: Invalid command sent to ExecuteXmlReader. The command must return an Xml result.
my code:
SqlDatabase
db = (
cmd = db.GetSqlStringCommand(
xmlReader = db.ExecuteXmlReader(cmd);
db = null;DbCommand cmd =
null;XmlReader xmlReader =
null;SqlDatabase)DatabaseFactory.CreateDatabase();"select
* from emp");DataSet ds = db.ExecuteDataSet(cmd);
View 1 Replies
Jun 8, 2010
How do I create a button which has the visible attribute which, when pressed, the code behind can reference values in the row it was on?
View 4 Replies
Sep 6, 2010
How do I create an ASP.Net MVC Helper for an Html.Label which takes in attributes? Currently when I define an Html.TextBox I am able to pass in a list of attributes. Sort of like below:
new {disabled="disabled", @class="pcTextBoxWithoutPaddingDisabled"})%>
However, it does not look as though the Html.Label has this feature. As a result, I have to define my labels using the label tag. Sort of like below: <label class="pcLabelBlackWithoutPadding"> I would like to be consistent I how my Html element get created. So, how do I create an Html.Label that will take in a list of attributes?
View 1 Replies
May 27, 2010
I want to create a custom attribute to check if the browser has cookies and javascript enabled. I'm guessing I would create a ActionFilterAttribute that would redirect to a controller action to load a page to check cookies and javascript on the client side. If they are enabled then it would redirect to the desired action, otherwise display an error message. Is this a correct approach or is there a better way to do this?
View 1 Replies
Mar 31, 2011
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" onchange="calculate()" runat="server" Text="0"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I'm getting this error on the above markup: Message 1 Validation (ASP.Net): Attribute 'onchange' is not a valid attribute of element 'TextBox'.
View 2 Replies
Mar 17, 2011
I have a problem with my web site 1stSigBdeAssn.org. I have made no changes to the site but I now get the following error message:
Parser Error Message:
Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
Source Error:
[code]....
View 4 Replies
Feb 1, 2011
I created a simple Master Page in Visual Studio 2008:
<%@
Master
Language="VB"
CodeFile="MasterPage.master.vb"
Inherits="MasterPage" %>
<!DOCTYPE
html
PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
and got green underlined 'Master' with two warning messages: 1.Validation (ASP.NET): This attribute name must be followed byan equal (=) sign and a value. If the value is in quotation marks, the quotation marks must match. 2. Validation (ASP.NET): Attribute 'Master' is not a valid attribute of element 'Control'.How I can get rid of the messages?
View 3 Replies
Jul 6, 2010
inside my model metadata, i have a timespan field that would like to display in all Create, Edit and Display views like "hh:mm". For this, is set DisplayFormatAttribute as follows:
[Code]....
When i try to create a new model object, the time field gets displayed as "00:00:00" im my model (00 is the initial values) instead of "00:00". Is there something i am doing wrong? Note that the same approach works for date fileds, where i want to be displayed as "dd/MM/yyyy" (for this is assign "{0:dd/MM/yyyy}" to the display format attribute).
View 4 Replies
Sep 17, 2010
I have a tag:
<asp:ListItem
CssClass="LabelCSS">Executive</asp:ListItem>
and I am getting the error message
Validation(ASP .Net):Attribute CssClass is not a valid attribute of element ListItem.
What attribute would I use for Css with ListItem?
View 2 Replies
Nov 29, 2010
i'm trying to host an .net framework4.0 application in IIS7. i got an error while clicking on the manage module in modules .like ("Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive. ") .I changed my application poll to .net4.0.I am able to browse my application
</system.serviceModel>
</configuration>
View 5 Replies
Oct 20, 2010
I installed Microsoft Visual Studio 2010 Ultimate Trial and converted existing asp.net 2.0 web application and I am getting this error: znrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive. It's coming from this section in the web.config which was auto-generated by VS2010 when I converted the project:
<compilation defaultLanguage="c#" debug="false" targetFramework="4.0">
<compilers>
<!--<compiler language="c#" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".cs" compilerOptions="/d:DEBUG;TRACE" /></compilers> -->
<compiler language="c#" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".cs"/></compilers>
<assemblies>
<add assembly="Microsoft.JScript, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
View 1 Replies
Aug 13, 2010
I am developing asp.net mobile application. I am using LINQ to XML to query XML file. I am using the following query to retrieve the name & value of the query dynamically as follows
var TotalManifolds = from MF in FieldRoot.Element("FIELD-DEFINITION").Element("MANIFOLDS").Elements("MANIFOLD")
join SLT in FieldRoot.Element("FIELD-DEFINITION").Element("SLOTS").Elements("SLOT")
on (string)MF.Attribute("MID") equals (string)SLT.Attribute("PARENT")
select new
{
SlotName = (string)SLT.Attribute("NAME").Value,
SlotValue = (string)SLT.Attribute("NAME").Value
};
In the following statement of above query I want to retrive the name of the attribure dynamically without explicitly specifying the name of the attribute SlotName = (string)SLT.Attribute("NAME").Value Here I am explicitly specifying the name. I want to code which can dynamically retrieve the name of the attribute. I am new to Linq to xml. how this can be done programatically? or can you provide me the link through which I can resolve the above issue ?
View 2 Replies
Jan 21, 2011
I am trying to achieve a SSO implimentation across my websites so i am using the machine key attribute to do so.now the trouble starts here as the website the user logs in is on the .net 1.1 framework and the website it it navigating to is .net 4.0.I have share the same machine-key across both the application . It works fine in my testing environment but as i move to the deployment server ,it just dosent work !So what i could do is read this article on MSDN :
http://msdn.microsoft.com/en-us/library/eb0zx8fc.aspx
this tells me to add a domin attribute like below
<forms loginUrl="~Login.aspx" defaultUrl="Default.aspx" protection="All" timeout="80" name=".ASPXAuth" domain="asbc.com"/>
but this thing just dosent work on the 1.1 application and throws an error Unrecognized attribute 'domain'.
Where do i get to mention the domin in my 1.1 application.?
View 3 Replies
Oct 22, 2010
I'm using webforms ASP.NET, with masterpages. I want to add a LANG attribute to the <title> tag. ASP.NET automatically generates a title tag. I've tried adding my own tag with an ID and runat="server", like this:
<title id="titleBlock" runat="server"></title>
When doing this, I can set an attribute like the following without any errors.
titleBlock.Attributes.Add("lang", "it");
However, ASP.NET wipes out my <title> tag completely and puts its own in without my LANG attribute. Is there any way to accomplish this?
View 1 Replies
Nov 8, 2010
What is the class attribute and how to use
View 1 Replies
Feb 18, 2010
I have a TextBox in my page
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="true"></asp:TextBox>
I am not able to get the changed value ( I have attached a ajax calender with this textbox)
in code behind because it is readonly
I can do this using TextBox1.Attributes.Add("readonly", "readonly"); or I can get the correct last value using Request.Form[TextBox1.UniqueID]
Why value is available when use code behind attribute add
View 6 Replies
Mar 29, 2011
In ASP.NET, you can add custom HTML tag attributes to a UserControl via
myLabel.Attributes['my-custom-attribute'] = "someValue";
// or Attributes.Add()
but how can I add an attribute that doesn't have a value? For example, (and I'm not saying that this is what I need) the W3C specification only needs the checked attribute present in a checkbox to consider it checked (instead of checked='true' or something).
<span ID="ctl-blah-blah-myLabel" my-custom-attribute>some text</span>
I'm looking into using something like this to tag specific elements on my page for some client-side behavior. I know that I can do the same with classes, but (1) classes are iffy to manipulate server-side, and (2) I kind of don't want to pollute my class declarations just for tagging (that may be weird for some, I know).
View 3 Replies
Jun 7, 2010
This may be something simple, but I am completely new to ASP.NET. I have been reading some tutorials based on W3Schools, and I have copied one of the files and tried to play with it by changing an element with a value to storing that same value in the attribute. Here is the edited XML (my.xml):
<?xml version="1.0" encoding="ISO-8859-1"?>
<countries>
<country>
<text value="N">Norway</text>
</country>
<country>
<text value="S">Sweden</text>
</country>
</countries>
I want to extract the N and S and use them as tooltips. Here is my aspx file:
<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycdcatalog=New DataSet
my.ReadXml(MapPath("my.xml"))
my.DataSource=my
my.DataBind()
end if
end sub
</script>
<html>
<body>
form runat="server">
<asp:Repeater id="my" runat="server">
HeaderTemplate>
table border="1" width="100%">
<tr>
<th>Name</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td title="<%#Container.DataItem.("text").Attributes["value"]%><%#Container.DataItem("text")%> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>
What have I missed here?
View 6 Replies
Jul 19, 2010
Why in asp.net web page we have only one FORM attribute, but in other language more than one FORM attribute is allowed.
View 3 Replies
Jan 26, 2011
I have the following method:
Code:
XmlNode AttributeNode = xmlDocument.CreateNode(XmlNodeType.Attribute, fieldName, WILTSNAMESPACE);
AttributeNode.Value = fieldValue;
parentNode.Attributes.SetNamedItem(AttributeNode);
this create (for example):
<Person d2p1:PersonRole="Boss">
How do I add an attribute without the d2p1: prefix:
<Person PersonRole="Boss">
View 5 Replies
Apr 7, 2010
Is it possible to set "for"(AssociatedControlID) attribute using jQuery? I am trying something like this to set it to the very next control that appears after label:
$('label.asssociateClass').each(function()
{
var toAssociate = $(this).next(':input');
$(this).attr("for", toAssociate.attr("id"));
});
The problem is that if I don't set it on a server through AssociatedControlID it never gets here since it's rendered as span instead of label in that case. Is there a way to overcome this or I have to do it on a server?
View 2 Replies
Jan 11, 2011
Is there an out-of-the-box DataAnnotation attribute that checks if an integer is greater than a certain value?
public Model
{
[GreaterThan(0)]
public int MyVal{get;set;}
}
View 4 Replies
Mar 16, 2011
Maybe this is dreaming, but is it possible to create an attribute that caches the output of a function (say, in HttpRuntime.Cache) and returns the value from the cache instead of actually executing the function when the parameters to the function are the same?
When I say function, I'm talking about any function, whether it fetches data from a DB, whether it adds two integers, or whether it spits out the content of a file. Any function.
View 5 Replies