473,570 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing <content:encode d> through JS

Hello,

I am here after head-banging with this issue for several days. I am
trying to parse a feed using JS and have stucked on the
<content:encode d> tag. I have tried getElementsbyTa gName but its not
working.

Any suggstions?

Kashif

Apr 8 '06 #1
7 6682


kashaziz wrote:
I am here after head-banging with this issue for several days. I am
trying to parse a feed using JS and have stucked on the
<content:encode d> tag. I have tried getElementsbyTa gName but its not
working.


Is that well-formed XML with namespaces meaning content is a prefix and
declared e.g. with
xmlns:content=" http://example.org/2006/whatever"
?
Then with Mozilla and with Opera use e.g.

xmlDocument.get ElementsByTagNa meNS('http://example.org/2006/whatever',
'encoded')
instead of getElementsByTa gName.
For IE 6 and MSXML 3 you can use XPath e.g.
xmlDocument.set Property('Selec tionLanguage', 'XPath');
xmlDocument.set Property('Selec tionNamespaces' ,
'xmlns:content= "http://example.org/2006/whatever"');
var encodedElements = xmlDocument.sel ectNodes('//content:encoded ');

Both getElementsByTa gNameNS and selectNodes can also be called on
element nodes instead on on the document node. But note that selectNodes
takes an XPath expression, use a relative expression e.g.
element.selectN odes('content:e ncoded')
or
element.selectN odes('.//content:encoded ')
to find elements relative to the element the method is called on.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 8 '06 #2
Martin Honnen wrote:
kashaziz wrote:
I am here after head-banging with this issue for several days. I am
trying to parse a feed using JS and have stucked on the
<content:encode d> tag. I have tried getElementsbyTa gName but its not
working.


Is that well-formed XML with namespaces meaning content is a prefix and
declared e.g. with
xmlns:content=" http://example.org/2006/whatever"
?
Then with Mozilla and with Opera use e.g.

xmlDocument.get ElementsByTagNa meNS('http://example.org/2006/whatever',
'encoded')
instead of getElementsByTa gName.
For IE 6 and MSXML 3 you can use XPath e.g.
[...]


The Gecko DOM has XPath support, too.

<URL:http://xulplanet.com/references/objref/>
<URL:http://kb.mozillazine. org/XPath>
<URL:http://developer.mozil la.org/en/docs/XPath>
PointedEars
Apr 8 '06 #3


Thomas 'PointedEars' Lahn wrote:

The Gecko DOM has XPath support, too.


Right, Opera 9 will also implement the W3C DOM Level 3 XPath API (only a
W3C note, not a recommendation) but to access elements in namespaced
documents safely getElementsByTa gNameNS is sufficient and much easier to
use than the W3C DOM Level 3 XPath API.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 8 '06 #4
The Feed is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="word press/1.5.2" -->
<rss version="2.0"
xmlns:content=" http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http ://wellformedweb.o rg/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"


<channel>
<title>Apnijobs .com: Jobs in Pakistan</title>
<link>http://www.apnijobs.co m</link>
<description>Wo rk for pleasure, not for creating more work - Search
Jobs in Pakistan and around the World.</description>
<pubDate>Mon, 27 Mar 2006 10:35:13 +0000</pubDate>
<generator>http ://wordpress.org/?v=1.5.2</generator>
<language>en</language>

<item>
<title>Teache rs Required for Nursery / Kindergarten and Junior School
(Karachi)</title>
<link>http://www.apnijobs.co m/teachers-required-for-nursery-kindergarten-and-junior-school-karachi.html</link>
<comments>htt p://www.apnijobs.co m/teachers-required-for-nursery-kindergarten-and-junior-school-karachi.html#co mments</comments>
<pubDate>Mon, 27 Mar 2006 10:34:17 +0000</pubDate>
<dc:creator>A li Asgher</dc:creator>

<category>Teach ing</category>
<category>Listi ng</category>
<category>Job s</category>
<guid>http://www.apnijobs.co m/teachers-required-for-nursery-kindergarten-and-junior-school-karachi.html</guid>
<description> <![CDATA[<p>School of excellence requires teachers for
Nursery / Kindergarten and Junior school Science teach...</p>
]]></description>
<content:encode d><![CDATA[<p>School of excellence requires teachers
for Nursery / Kindergarten and Junior school Science teacher for
immediate appointment. </p>

<p>Contact 021-4981303, 4816345.</p>

<p>Address: D-2, Block-4, Gulshan-e-Iqbal, Karachi.</p>

<p>E-mail: so*@cyber.net.p k</p>
]]></content:encoded >
<wfw:commentRSS >http://www.apnijobs.co m/teachers-required-for-nursery-kindergarten-and-junior-school-karachi.html/feed/</wfw:commentRSS>
</item>
--------------------------------------------------------------------------------------------------------

and the code is:
for (var i=0; i<this.feeditem s.length; i++){
if(i==this.feed _id){
var feedfound=1
this.title[i]=this.feeditems[i].getElementsByT agName("title")[0].firstChild.nod eValue

this.link[i]=this.feeditems[i].getElementsByT agName("link")[0].firstChild.nod eValue

this.descriptio n[i]=this.feeditems[i].getElementsByT agName("descrip tion")[0].firstChild.nod eValue

this.pubdate[i]=this.feeditems[i].getElementsByT agName("pubDate ")[0].firstChild.nod eValue
tickercontent = "<a
href="+this.lin k[i]+">"+this.ti tle[i]+"</a>"+"<br/>"

}
}

Apr 8 '06 #5


kashaziz wrote:
The Feed is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="word press/1.5.2" -->
<rss version="2.0"
xmlns:content=" http://purl.org/rss/1.0/modules/content/" <content:encode d><![CDATA[<p>School of excellence requires teachers
for Nursery / Kindergarten and Junior school Science teacher for
immediate appointment. </p>

<p>Contact 021-4981303, 4816345.</p>

<p>Address: D-2, Block-4, Gulshan-e-Iqbal, Karachi.</p>

<p>E-mail: so*@cyber.net.p k</p>
]]></content:encoded >


Then use the already suggested code, the above is XML with namespaces so
with Mozilla and Opera make use of the W3C DOM Level 2 namespace aware
methods like getElementsByTa gNameNS e.g.
var encodedElements = xmlDocument.get ElementsByTagNa meNS(
'http://purl.org/rss/1.0/modules/content/',
'encoded'
);
Then you get a DOM NodeList the same as with getElementsByTa gName so you
should know how to loop through. Only note that the contents of those
content:encoded elements seems to be a single CDATA section node to
escape HTML markup snippets. You can read out that HTML markup snippets
as text (e.g. encodedElements[0].firstChild.dat a) but inside of a CDATA
section it will not be parsed into nodes.

And for IE 6/MSXML 3 you can use selectNodes and XPath 1.0 to get a DOM
NodeList as suggested
xmlDocument.set Property('Selec tionLanguage', 'XPath');
xmlDocument.set Property('Selec tionNamespaces' ,
'xmlns:content= "http://purl.org/rss/1.0/modules/content/"');
var encodedElements = xmlDocument.sel ectNodes('.//content:encoded ');
--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 9 '06 #6
I have tried var encodedElements = xmldata.getElem entsByTagNameNS (
"http://purl.org/rss/1.0/modules/content/", "encoded"); but it returns
a 0 length value.

Apr 11 '06 #7
Any suggestion guys?

Apr 20 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2950
by: Francesco Moi | last post by:
Hello. I'm trying to build a RSS feed for my website. It starts: ----------------//--------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd"> <rss version="0.91"> ----------------//----------------------
2
2311
by: Gill Bates | last post by:
I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest version is: Dim myWebClient As New WebClient Dim nvc As New NameValueCollection nvc.Add("Login", username) nvc.Add("Password", password)
17
2158
by: ccdrbrg | last post by:
This is a rather general subject, I apologize. I am new to XHTML, CSS, et al and I am having trouble understanding the DTD and xml namespace declarations. For example: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DT¬D/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"...
28
2910
by: dingbat | last post by:
I'm writing a "tabbed folder" nav bar. Site standards are graphical prettiness, CSS throughout, valid code, but accesibility is ignored where it conflicts with prettiness. The particular issue here is that the graphic designer wants a pretty (non-webbable) font on the shaded nav tabs, so I'm reduced to using bitmaps. To make the 4-way...
16
4883
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be...
4
3020
by: David Lozzi | last post by:
Howdy, I'm using a WYSIWYG editor called TinyMCE. When I edit some text and then save it back to my SQL server using a SQLCommand, all HTML characters are changed to HTML code, i.e. &gt;strong&lt; instead of <strong> and so on. Is this a problem with the editor or something else? Does .Net convert it? I had to disable page validate request...
12
1550
by: Christian Roth | last post by:
Hello, I am merely asking this for my own understanding: Processing instruction's data part is not entity-aware, i.e. character and numercial entities are not resolved at parsing time. E.g., <?mypi &lt;par/&gt; ?> delivers as data part the String(!) "&lt;par/&gt;".
4
9063
by: SammyBar | last post by:
Hi all, I wonder is it possible to upload the content of an <imgfield to a server. The content of the <imgwas downloaded from a web site different from the one it should be uploaded. The image file should not be saved locally before uploading. It should not be visible any <input type=file on the form. How can it be done? I'm working on a...
5
14401
by: magix | last post by:
Hi, with: <Input type="file"...> it will let the user to click to "browse" button to browse for files, question is how can I limit the file type to be only jpg and gif extension, when the browse window open ? thank you.
0
7726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7636
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7948
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6329
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5523
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.