ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

C# and XML Problem - any help please?

(1/1)

Redhat:
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# ---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:
Maybe this will help (note: which is a random page I found) -> http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php

Ath:
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?

Redhat:
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!

Navigation

[0] Message Index

Go to full version