Archive for category XML
I had a Label control that I wanted to populate from a resource file, like so:
<asp:Label ID="lblNote" runat="server" Text="<%$ Resources:AppInfo, Note%>" />
I needed to put a line break in the middle of the text. To do that, I wanted to put a “<br>” in the text, but since the resource file complained when I tried to put greater than and less than symbols, I had to be sly about it. So in the AppInfo.resx file, I had this entry to add a line break:
<data name="Note" xml:space="preserve"> <value>Note: I want this to be the first line and <br>this to be the second.</value> </data>
I’ve been working with XML files being returned from the Flickr web service. The authentication scheme for Flickr using their APIs is a little involved, and I’ll get more into that process in a future blog post.
One step in the authentication process is returning a “frob” for a Flickr application. The results of the request are in XML format (unless you choose differently) and look like this:
<rsp stat="ok"> <frob>72157625513700330-d4435917b66c4c17-220944</frob> </rsp>
I was doing this asynchronously, and the results were returned as a stream. Here is my finished function, which converts the stream (the parameter e.Result is a stream) into a string and uses XmlDocument.LoadXml to load the XML:
XmlDocument doc = new XmlDocument(); StreamReader Reader = new StreamReader(e.Result); doc.LoadXml(Reader.ReadToEnd()); XmlNodeList Node = doc.GetElementsByTagName("frob"); Response.Write(Node.FirstChild.Value);
Afterwards, a simple called to the XmlNodeList.GetElementsByTagName to retrieve the correct tag, and a call to the FirstChild property of the XML node, was all that was needed.