Your error has nothing to do with XML itself. The call to DataNode.SelectSingleNode probably returns null. In fact, directly calling methods on method calls that are prone to return null is one of the worst coding habit someone can have.Here is what a good programmer would have done:
userid = DataNode.SelectSingleNode("Username");
if ((userid != null) && (!String.IsNullOrEmpty(userid.InnerText))
{
// Do your stuff
}
else
{
throw new NoUsernameNodeException();
}
Not checking for null values before using object references is one the worst thing to do, always leading to obscure error message "Object reference not set to an object".
Found solution. Here's ASP.net code in case it helps anyone else: <pre> <asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1" BackColor="#333333" BorderStyle="None" GridLines="Vertical" BorderColor="#333333" BorderWidth="0px"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%#XPath("pubDate")%>' Font-Names="Verdana" Font-Size="XX-Small"></asp:Label><br /> <asp:HyperLink ID="HyperLink1" runat="server" Text='<%#XPath("title")%>' NavigateUrl='<%#XPath("link")%>' Target="_blank" Font-Names="Verdana" Font-Size="Small"></asp:HyperLink><br /> <asp:Label ID="description_label" runat="server" Text='<%#XPath("description")%>'></asp:Label><br /> <br /> </ItemTemplate> </asp:DataList> Here's the code behind: <pre> Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound Dim ShortDescriptionLabel As Label = CType(e.Item.FindControl("description_label"), Label) If ShortDescriptionLabel.Text.Length > 200 Then ShortDescriptionLabel.Text = ShortDescriptionLabel.Text.Substring(0, 200) & "..." End If ShortDescriptionLabel.Text = ShortDescriptionLabel.Text End Sub
Your question involves LINQ usage. Thus, you should post it under the .NET Framework forum. Since it is written in Visual Basic, you could have place it there as a second choice. However, you should still only post it in one forum.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Saturday, March 28, 2009 5:11 PM
The document element is the top most "parent" node. Also, your example code is not showing.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
Tejabhiram wrote:
Could u please specify as to where shud i place these tags in my XSL Document
I don't know what tags you are talking about. I you attempted to post XML on this forum you failed. Read the posting instructions. If you do not know how to use XSLT there are good tutorials on www.w3schools.com
XML is just markup, it doesn't specify how things should look. It sounds as if you might need a markup language directed towards chemical formulas. I did a search and found CML - Chemical Markup Language: http://www.ch.ic.ac.uk/rzepa/cml/[^]. Maybe that's what you're looking for. Scott
ahmedsamir wrote:
I have a SQL2005 database and need to convert it to XML database to use it in a website using ASP.Net.
That makes no sense. It is very likely that you don't understand the technologies you are attempting to use well enough to be using them. If that is the case you need to be reading rather than posting in internet forums.
CrimeanTurtle2008 wrote:
but just does not work.
You might need to provide more specific information than that.
CrimeanTurtle2008 wrote:
My question is, is it possible to create this XML file from a single table
Of course it's possible. However if you are limited in the "how" it might not be. Based on your post it really sounds like you are trying to accomplish your goal using SQL Server XML generation tools. If you are limiting your solution to that then this is probably not a good forum since this is an XML forum not a SQL Server forum. In any case questions about generating XML are more about the tools you are using to do the generation and using the source data with those tools, than about XML as a subject.
The serialization only class members will be serialized. Therefore, we need to use with XslCompiledTransform class. From microsoft web site: http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx[^] Ido
sonukadole wrote:
ANy help on this is appriciated.
Try asking an actual question. Be specific and provide information that we might need to help you. We are not with you so we can't see and know what you are doing and working with unless you tell us.
Hello again. If you don't respond to people posting replies to your questions, you won't often receive help from people on this site. You are asking yet another question and we still don't know any information about your development and runtime platforms and which XML library you are using. Shall we try this again?
I solve my problem; I write this code top of the page and under <xsl:stylesheet xm...> tag; <xsl:key name="unique-orders" match="Order/Shopping/ID" use="." /> First for-each statement <xsl:for-each select="Order/Shopping/ID[generate-id() = generate-id(key('unique-orders', .))]"> Second for-each statement <xsl:for-each select="/Order/Product[ProductID = current()]">
rustyamigo wrote:
Mozilla Firefox 3.0. Could you please let me know the equivalent code for transformation of XML document.
Sure, see if this[^] helps Good luck
Ok... I found the answer to my own question(below), but can I achieve the same result some other way, so I don't have to create nodes for it? It is very time consuming to edit the text in that manner... Thanks again! ________________________________ <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="r"> <font color="red">xsl:apply-templates/</font> </xsl:template> <xsl:template match="g"> <font color="green">xsl:apply-templates/</font> </xsl:template> </xsl:stylesheet> ____________________________________