Archive for category XML

Putting a line break in an resx resource file

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 &lt;br&gt;this to be the second.</value>

Leave a comment

Loading an XML file from a stream

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">

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);
            XmlNodeList Node = doc.GetElementsByTagName("frob");

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.

Leave a comment