Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • August 31, 2015, 10:55:41 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: C# and XML Problem - any help please?  (Read 1648 times)

Redhat

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 249
    • View Profile
    • Matt Harwood Consultancy
    • Donate to Member
C# and XML Problem - any help please?
« on: April 13, 2012, 09:51:38 PM »
Hi all  :tellme:

Someone's let me loose with C#.

I've nearly finished a podcast downloader application, and I'm ironing out several bugs. One of which is that I have some code that is using XmlDocument.SelectSingleNode:

Code: C#
  1. XmlNode node = doc.SelectSingleNode("rss/channel/item/title[.=\'" + episode + "\']");
  2.  

Now, there is a bug when the episode variable has a colon ( : ) in it - I'd guess because it thinks I'm declaring a namespace or something.

Does anyone have a suggestion of how to escape the : character in a string please?

Many thanks!

hamradio

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 637
  • Amateur Radio Guy
    • View Profile
    • HamRadioUSA.net
    • Donate to Member
Re: C# and XML Problem - any help please?
« Reply #1 on: April 13, 2012, 11:02:05 PM »
Maybe this will help (note: which is a random page I found) -> http://www.theukwebd...scape-characters.php
Carroll - HamRadioUSA.net

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,533
    • View Profile
    • Donate to Member
Re: C# and XML Problem - any help please?
« Reply #2 on: April 14, 2012, 03:53:04 AM »
This seems helpful: http://stackoverflow...acter-in-xpath-query but it's about single and double quotes mostly.

Guess you're in a deadlock, this XML spec detail seems to say you can't have a colon in an ordinary node name, but it's referring to an, obviously non-declared, namespace.
Escaping special characters is imho limited to the content part of XML, not the structure part.

You should be able to read your data though, by iterating over all the elements 1 level higher in the XML structure, and that would be /item/, right?

Redhat

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 249
    • View Profile
    • Matt Harwood Consultancy
    • Donate to Member
Re: C# and XML Problem - any help please?
« Reply #3 on: April 14, 2012, 10:34:04 AM »
Thanks a lot for the replies ham and Ath - very useful.

I'll try iterating over the parent node - and also try deleting all colons from the XML file (apart from actual namespaces) and then reading the file with the "query term" de-coloned too :)

I'll let you know if I'm successful.. thanks again!