DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

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

Redhat

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 254
C# and XML Problem - any help please?
« on: April 14, 2012, 02:51 AM »
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: (csharp)
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

  • Amateur Radio Guy
  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 893
    • Plugin Coding Medal
    • Participated in NANY Challenge Fifteen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
    • Hardware Hacker
Re: C# and XML Problem - any help please?
« Reply #1 on: April 14, 2012, 04:02 AM »
Maybe this will help (note: which is a random page I found) -> http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: C# and XML Problem - any help please?
« Reply #2 on: April 14, 2012, 08:53 AM »
This seems helpful: http://stackoverflow.com/questions/1341847/special-character-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?
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

Redhat

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 254
Re: C# and XML Problem - any help please?
« Reply #3 on: April 14, 2012, 03:34 PM »
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!

Original address: https://www.donationcoder.com/forum/index.php?topic=30661.0