How to access Xml Node with name formed only by numbers using C# and XPath

consider this following XML generated by one tool:

<root>
    <GameToVideoMap>
        <200000001120460>
            <VideoThumbnailUrl>URL Text</VideoThumbnailUrl>
            <VideoUrl>Text</VideoUrl>
            <Title>Text</Title>
        </200000001120460>
        <13131>
            <VideoThumbnailUrl>URL Text</VideoThumbnailUrl>
            <VideoUrl>Text</VideoUrl>
            <Title>Text</Title>
        </13131>
        <2>
            <VideoThumbnailUrl>URL Text</VideoThumbnailUrl>
            <VideoUrl>Text</VideoUrl>
            <Title>Text</Title>
        </2>
    </GameToVideoMap>
</root>

Where GameToVideoMap is a dictionary. I want to access the URLs using a XPath string generated by some function. So I would have the following command:

string path = "/root[1]/GameToVideoMap[1]/200000001120460[1]/VideoThumbnailUrl[1]";
XmlNode targetNode = targetDoc.SelectSingleNode(path);

The problem is that the SelectSingleNode raises an exception “Expression must evaluate to a node-set.”. If I use the path only as:

string path = "/root[1]/GameToVideoMap[1]";

Then if works nicely and I can see that it has a child node named “200000001120460” on the debug mode on Visual Studio like it is on the XML document. So I think that my problem is that the node’s number is formed only by digits. Is there a way to escape the name of the node to be able to use the XPath query for a XML in that format? Or am I doing something wrong that I didn’t notice. Thanks for the time.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s