开发者

Parsing url from xml file?

I have a xml file having the tags like

<link>
        <linkto>http://www.ezstream.com/broadcasts/index.cfm?fuseaction=usrbrd&broadcasterid=57468开发者_JS百科</linkto>
        <image>report_button</image>    
        <alt>Report a Problem</alt> 
        <target></target>
</link>

<linkto> tag have the url. But because of the "&" symbol in the url thats completely crashing the page. I tried using like

amp; next to the & symbol but this doesn't give the correct url. PLease help me

Thanks


Well, if the XML contains a bare & as in your example, then it is not valid XML. If your XML parser refuses to parse this, it is expected behaviour.

The XML is supposed to contain &amp; instead. Any reasonable XML parser will automatically parse this properly and replace &amp; with & before returning the URL to you. If this is not the case, your XML parser has a bug.

If you are trying to retrieve the URL using anything other than an XML parser (e.g. a regular expression?), then you should consider using an XML parser.


If you are parsing this yourself then its important to note that this is not valid XML. The escape sequence should be &, and if you want it completely escaped it would be &amp;

You will then need to either URL escape the string, or URL unescape the string depending on how it ends up encoded, and what you intend to do with it.

Its not clear from your question where the actual error lies (in your parsing, or the renderring). You can find URL escape/unescape functionality in the helper classes inside of System.Web in the HttpUtility static classes.


These escape sequences that represent single characters are actually called character references in XML. There are a handful of predefined character references that you can use when working with XML. The predefined characters are:

Ampersand—&—&amp;
greater-than—>—&gt;   
less-than—<—&lt; apostrophe—'—&apos;
quote—"—&quot;

Please try with this...

Beware of the ampersand when using XML

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜