topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Friday December 13, 2024, 9:23 pm
  • Proudly celebrating 15+ 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 5053 times)

Redhat

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 254
    • View Profile
    • Donate to Member
C# and XML Problem - any help please?
« on: April 13, 2012, 09:51 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# [Select]
  1. XmlNode node = doc.SelectSingleNode("rss/channel/item/title[.=\'" + episode + "\']");

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: 884
  • Amateur Radio Guy
    • View Profile
    • HamRadioUSA.net
    • Read more about this member.
    • Donate to Member
Re: C# and XML Problem - any help please?
« Reply #1 on: April 13, 2012, 11:02 PM »
Maybe this will help (note: which is a random page I found) -> http://www.theukwebd...scape-characters.php

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: C# and XML Problem - any help please?
« Reply #2 on: April 14, 2012, 03:53 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: 254
    • View Profile
    • Donate to Member
Re: C# and XML Problem - any help please?
« Reply #3 on: April 14, 2012, 10:34 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!