473,796 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementById does not work on returned value of DOMParser.parse FromString()

I am working on a code where I am loading XML data from a file on the
server using
.......
if (xmlhttp.readyS tate==4) {
value=xmlhttp.r esponseText;
var parser=new DOMParser();
xml=parser.pars eFromString(val ue,"text/xml")
........
when I use getElementsByTa gName I get
============fir ebug output========= =
>>xml.getElemen tsByTagName('fo o')
[<foo address="0x4123 " id="001" name="isp1582">]

alert(xml.getEl ementsByTagName ("module") === null) gives FALSE
============End firebug output========= =
but on using getElementById I get
=============== Firebug Output========= ======
alert(xml.getEl ementById("001" ) === null) gives TRUE
>>xml.getElemen tById("001")
=============== End FirebugOutput== ==========

I am expecting xml.getElementB yId("001") to return the same node as
xml.getElements ByTagName('foo' )[0]
Am I missing something?
I am using firefox version 1.5.0.9

Jan 31 '07 #1
3 9682
On Jan 31, 8:32 pm, "edai" <edain...@gmail .comwrote:
I am working on a code where I am loading XML data from a
file on the server using
[...]
var parser=new DOMParser();
xml=parser.pars eFromString(val ue,"text/xml")
I am expecting xml.getElementB yId("001") to return the
same node as xml.getElements ByTagName('foo' )[0]
Am I missing something?
I believe getElementById( ) does not look up an element with
the id attribute that equals to the value you've provided.
Instead, it looks up an element with the attribute
*defined* as an ID (in DTD or XML Schema--but I don't think
I've heard of browsers supporting schemata) that equals to
the value you've provided. Basically, you'll need a DTD for
the XML you're trying to work with if you want to use
getElementById( ).

I might be wrong, so I'd suggest doing some reading on the
subject, the relevant materials should be relatively easy
to obtain on the net.

--
Pavel Lepin

Feb 1 '07 #2
On Feb 1, 12:40 pm, p.le...@ctncorp .com wrote:
On Jan 31, 8:32 pm, "edai" <edain...@gmail .comwrote:
I am working on a code where I am loading XML data from a
file on the server using

[...]
var parser=new DOMParser();
xml=parser.pars eFromString(val ue,"text/xml")
I am expecting xml.getElementB yId("001") to return the
same node as xml.getElements ByTagName('foo' )[0]
Am I missing something?

I believe getElementById( ) does not look up an element with
the id attribute that equals to the value you've provided.
Instead, it looks up an element with the attribute
*defined* as an ID (in DTD or XML Schema--but I don't think
I've heard of browsers supporting schemata) that equals to
the value you've provided. Basically, you'll need a DTD for
the XML you're trying to work with if you want to use
getElementById( ).

I might be wrong, so I'd suggest doing some reading on the
subject, the relevant materials should be relatively easy
to obtain on the net.

--
Pavel Lepin
You are right. I was able to find a discussion on this issue at http://
http://www.subbu.org/weblogs/main/20...nd_getele.html
For the time being I have changed my xml file to have header similar
to an xhtml file and it seems to be working.
i.e added
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
to the top and encapsulated the data in
<html xmlns="http://www.w3.org/1999/xhtml">
</html>

Feb 1 '07 #3
On Feb 1, 4:00 pm, "edai" <edain...@gmail .comwrote:
On Feb 1, 12:40 pm, p.le...@ctncorp .com wrote:
On Jan 31, 8:32 pm, "edai" <edain...@gmail .comwrote:
var parser=new DOMParser();
xml=parser.pars eFromString(val ue,"text/xml")
I am expecting xml.getElementB yId("001") to return
the same node as xml.getElements ByTagName('foo' )[0]
Am I missing something?
I believe getElementById( ) does not look up an element
with the id attribute that equals to the value you've
provided. Instead, it looks up an element with the
attribute *defined* as an ID (in DTD or XML Schema--but
I don't think I've heard of browsers supporting
schemata) that equals to the value you've provided.
Basically, you'll need a DTD for the XML you're trying
to work with if you want to use getElementById( ).

You are right. I was able to find a discussion on this
issue at
http://www.subbu.org/weblogs/main/20...nd_getele.html
For the time being I have changed my xml file to have
header similar to an xhtml file and it seems to be
working.
Note that, unless I'm much mistaken, while this might work,
it is not *guaranteed* to work unless the document you're
dealing with is valid according to the doctype you've
provided. While this is obviously workable as a temporary
solution, for long-term I'd recommend writing your own
simple DTD for the documents you're working with. (Dropping
getElementById( ) altogether is another solution.
Implementing your own getElementById( ) not relying on DTD
shouldn't be much of a problem either.)

--
Pavel Lepin

Feb 1 '07 #4

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

Similar topics

0
2178
by: Faisal | last post by:
I have a question regarding the "PublicKeyToken" attribute of the "<section>" tag in the web.config file. Pretty much most references have this value set to "b77a5c561934e089"; the same value as in the machine.config file <configSections <section name="sampleSection" type="System.Configuration.SingleTagSectionHandler, System,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" / </configSections My question is, does the...
1
3777
by: Tim Begin | last post by:
I am attempting to use the ThreadPool.SetMinThreads method as shown in the MSDN example code: int minWorker, minIOPort; int newWorker,newIOPort; ThreadPool.GetAvailableThreads(out minWorker, out minIOPort); bool flag = ThreadPool.SetMinThreads(4, minIOPort); ThreadPool.GetAvailableThreads(out newWorker, out newIOPort); After running this flag is true, but the worker value is still set to 25. I am using .Net 1.1.4322 and this call was...
2
1535
by: Jiggaz | last post by:
Hi, I have a stored procedure (ms sql 2005) which is return add the user in the table USERS. But the sp (stored proc) tests if a user with the desired nickname already exists. If exists, return -1 otherwise return 1 and execute the INSERT query! But, how to get the returned value from the stored procedure (called : CreateAccount) in ASP.NET ?
5
8091
by: Dmitriy Lapshin [C# / .NET MVP] | last post by:
Hi all, I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right thing to do. And I wonder why VB .NET keeps silence and makes such function return some default value instead. Isn't it error-prone? -- Dmitriy Lapshin
0
1410
by: Xavier | last post by:
hello, how can i display the returned value of a SqlDataSource in a Label <asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:Pubs %>" ID="SqlDataSource1" runat="server" SelectCommand="SELECT Top 1 LastName,Name FROM mytable where ......"></asp:SqlDataSource>
3
9969
by: sfeher | last post by:
Hi All, The following code returns a valid xmlDoc (since I can evaluate and selectNodes) but its value is "xmlDoc= null" ?! Or at least this is what the FireBug shows and (xmlDoc===null) is true. var parser = new DOMParser(); var xmlDoc = parser.parseFromString( responseText, "text/xml"); // at this point: xmlDoc= null
6
2531
by: ewolfman | last post by:
Hi, Is there any way in which I can monitor / hook the Registry, and upon a call to a specific key from a specific application - swap the returned value? I was thinking of using this method to overcome the "click" sound of the WebBrowser, without having to affect the Registry permanently. This way I could monitor the call for the sound file to be played (located in
8
3119
by: Samik R. | last post by:
Hello, I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I press a button in the first page. The returned HTML in the div has another button, which, when pressed, should call the same perl script again. Think of the program as some sort of wizard. The problem is, this works perfectly as expected in FF...
5
5776
by: jhappeal | last post by:
I do not know Javascript that well so I might be going about this the wrong way. Any help would be appreciated. This function attempts to hide the options inside of the optgroup tag of the second select box based on the user selected option of the first select box. It works fine in Mozilla but IE7 still shows all the optgroups in the second select box. The idea is to show the appropriate list of states based on what country a user selects...
0
9685
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10467
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5454
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.