Search This Blog

Getting XML Text From XML Nodes

I've been working with XML very heavily the past couple of weeks, and for whatever reason this is just one of those things I haven't had to do a whole lot of until now. Don't get me wrong, XML comes up pretty regularly for most people, but I haven't had to live and breathe it this much before.

As with most things in ColdFusion it's incredibly easy to jump in and get going, and for what I'm doing anyway, XmlSearch makes it absolutely trivial to tear through the XML and get the data I need.

I did run into one annoyance and thought I'd see if anyone had a better solution. Again, since I seem to have dodged working with XML this heavily until now I could just be missing something. Specifically I'm referring to the seeming necessity of two lines to get at most things when you use XmlSearch. If you've worked with XML much in CF you probably already know what I mean. Let's assume there's a single node (meaning really a single element array with an XML node in it) returned by this:

<cfset myXmlNode = XmlSearch(myDoc, "/*/myNode") />

To get at the XmlText, I then have to do this:

<cfset myXmlText = myXmlNode[1].XmlText />

What I'd like to be able to do is this:

<cfset myXmlText = XmlSearch(myDoc, "/*/myNode")[1].XmlText />

But unfortunately that syntax isn't valid. To solve the problem I wrote a little UDF called getXmlTextFromXmlSearch (couldn't think of a longer name ;-) that takes in the array and the element number from which you want the XmlText. It works, but I'm a tad irked that this seems to be necessary. What CF could use IMO is an ArrayGetAt *function* so you could wrap arrays in the function instead of having to jump through these other hoops:

and i coulnd't for the life of me figure out how to get the xpath search down to just xmlValue...becasue it appears that CF is building that DOM node structure back in to the xmlSearch response. so, xPath finds the text, gives it back to CF, and CF goes 'well, hell, this looks like xml, so let's send it back as native CF XML DOM node structure. as it turns out, in CF8, at least, if i output arr[1], i get a string, and not the XML object shown in the dump of the array.

Comments

Popular posts from this blog

This is a first for me since under normal circumstances we run all our Django applications on Linux with Nginx, but we're in the process of developing an application for another department and due to the requirements around this project, we'll be handing the code off to them to deploy. They don't have any experience with Linux or web servers other than IIS, so I recently took up the challenge of figuring out how to run Django applications on Windows Server 2012 with IIS.

Based on the dated or complete lack of information around this I'm assuming it's not something that's very common in the wild, so I thought I'd share what I came up with in case others need to do this.

If you follow me on Google+ you'll know I had a recent rant about Windows Media Center, which after running fine for about a year suddenly decided as of January 29 it was done downloading the program guide and by extension was therefore done recording any TV shows.

I'll spare you more ranting and simply say that none of the suggestions I got (which I appreciate!) worked, and rather than spending more time figuring out why, I decided to try something different.

NextPVR is an awesome free (as in beer, not as in freedom unfortunately ...) PVR application for Windows that with a little bit of tweaking handily replaced Windows Media Center. It can even download guide data, which is apparently something WMC no longer feels like doing.

Background
I wound up going down this road in a rather circuitous way. My initial goal for the weekend project was to get Raspbmc running on one of my Raspberry Pis. The latest version of XBMC has PVR functionality so I was anxious to try that out as a …

My setup for my day job these days is a Surface Pro 4 and either an LG 34UC87M-B or a Dell P2715Q monitor, depending on where I'm working. This is a fantastic setup, but some applications have trouble dealing with the high pixel density and don't scale appropriately.
One case in point is Skype for Business. For some reason it scales correctly as I move between the Surface screen and the external monitor when I use the Dell, but on the LG monitor Skype is either massive on the external monitor, or tiny on the Surface screen.
After a big of digging around I came across a solution that worked for me, which is to change a setting in Skype's manifest file (who knew there was one?). On my machine the file is here:
C:\Program Files\Microsoft Office\Office16\LYNC.EXE.MANIFEST
And the setting in question is this:<dpiAware>True/PM</dpiAware>
Which I changed to this:
<dpiAware>False/PM</dpiAware>
Note that you'll probably have to edit the file as administr…