473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

XML DOM troubles

** I tried to find a more suitable NG for this issue but didn't find much
(on the MS server) the ones I did find haven't had posts in a loooong time.
Sorry for the somewhat off topic post **

My Situation:
client side scripts make an ajax request for some data
aspx page processes request and writes back an XML (not perfectly formed)
file
client side script receives data and attempts to parse the XML (this is
where I'm having a hard time)

Here is a sample of what the XML looks like:
[xml sample]
<?xml version="1.0" encoding="utf-8" ?>
<MedicalProfessionals>
<count>3</count>
<MedicalProfessional>
<FirstName>David</FirstName>
<LastName>Jones</LastName>
<Address1>123 SomeStreet</Address1>
<Address2>Suite #4</Address2>
<City>Irvine</City>
<State>California</State>
<ZipCode>92614</ZipCode>
<Phone>949-333-2222</Phone>
<AltPhone>949-888-9874</AltPhone>
<Fax>949-111-2345</Fax>
<Notes>This is a good Dr.</Notes>
<UPIN>11223344</UPIN>
<NSInternalID>1</NSInternalID>
</MedicalProfessional>
</MedicalProfessionals>
[/xml sample]

Here is some of the client parsing script:
[client script parsing code]
medicalProfessionals =
medProdXMLDoc.getElementsByTagName("MedicalProfess ional");
alert('number of medical professionals returned: ' +
medicalProfessionals.length);
alert(medicalProfessionals[0].childNodes.length);
for(i = 0; i < medicalProfessionals[0].childNodes.length; i++)
{
alert(medicalProfessionals[0].childNodes[i].nodeName);
alert(medicalProfessionals[0].childNodes[i].nodeValue);
}
[/client script parsing code]

When the above codes runs, it correctly reports the length of
medicalProfessionals
It correctly reports the number of childNodes
It correctly reports the NAME of the child nodes in the loop
It reports null for all the child node values - this is the part that is
kicking my butt.

I have checked that the XML being sent to the client is populated with data
for those nodes and it is. I really don't know why it would report them as
null.

Does anyone see a problem with this code? Any ideas? I'm about to revert
to a delimited string and parse the "old fashioned" way but I would much
rather use XML.

2 more questions:
1) Is there a way to load an XML STRING using firefox? I have been trying
to pass the string to the load() method of the firefox XML Dom Parser object
but it wants a file path. Any ideas?
2) Is there a way to access a childNode by nodeName instead of index? I
hate accessing things by index as it's so prone to bugs. I know I can
implement a search function to find them, but it sure seems like this is
something that should be available out of the box. maybe I'm missing it?

Thanks for reading and again, sorry for the off topic post, but you guys are
all very knowledgeable with web technologies and I didn't know where else to
turn. :0)

-Steve
Sep 18 '06 #1
2 2058


sklett wrote:

<MedicalProfessional>
<FirstName>David</FirstName>
medicalProfessionals =
medProdXMLDoc.getElementsByTagName("MedicalProfess ional");
alert('number of medical professionals returned: ' +
medicalProfessionals.length);
alert(medicalProfessionals[0].childNodes.length);
for(i = 0; i < medicalProfessionals[0].childNodes.length; i++)
{
alert(medicalProfessionals[0].childNodes[i].nodeName);
alert(medicalProfessionals[0].childNodes[i].nodeValue);
}
[/client script parsing code]

When the above codes runs, it correctly reports the length of
medicalProfessionals
It correctly reports the number of childNodes
It correctly reports the NAME of the child nodes in the loop
It reports null for all the child node values -
Well in the DOM if you have an element node then nodeValue is defined as
null. It is _not_ the text content of the element. If you want that then
you need the text property for MSXML or textContent for Firefox/Mozilla
or Opera 9.
And if you script XML on the web then be aware that the different
parsers your script will encounter might treat white space different,
for instance Mozilla will have text nodes with white space between
element nodes. So a script looking for an element node with e.g.
childNodes[certainIndex] might find an element node with one parser
(e.g. MSXML) but a text node with another parser (e.g. Mozilla). Thus if
you are looking for element child nodes then if you loop through
childNodes or index it check the nodeType, or better yet don't use
childNodes but rather XPath (e.g. selectSingleNode/selectNodes with
MSXML, DOM Level 3 XPath API with Mozilla and with Opera 9) to look for
the child elements.


Client-side scripting questions are better asked in comp.lang.javascript
or if they relate to XML in comp.text.xml. The Microsoft server has
microsoft.public.xml for instance and various JScript scripting groups.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 18 '06 #2
Hi Martin,

Thank you for the post. I have added the xml newsgroup and will try out
Google groups to access the others (my ISP doesn't have a news server that I
can use)

I'm not sure if it's appropriate for me to continue this thread here now
that you have directed me to the NGs so I will take the issue over to one of
them, hopefully you are active on the other NGs so we can pick this up again
;0)

Have a good day,
Steve
"Martin Honnen" <ma*******@yahoo.dewrote in message
news:eV**************@TK2MSFTNGP05.phx.gbl...
>

sklett wrote:

> <MedicalProfessional>
<FirstName>David</FirstName>

> medicalProfessionals =
medProdXMLDoc.getElementsByTagName("MedicalProfes sional");
alert('number of medical professionals returned: ' +
medicalProfessionals.length);
alert(medicalProfessionals[0].childNodes.length);
for(i = 0; i < medicalProfessionals[0].childNodes.length; i++)
{
alert(medicalProfessionals[0].childNodes[i].nodeName);
alert(medicalProfessionals[0].childNodes[i].nodeValue);
}
[/client script parsing code]

When the above codes runs, it correctly reports the length of
medicalProfessionals
It correctly reports the number of childNodes
It correctly reports the NAME of the child nodes in the loop
It reports null for all the child node values -

Well in the DOM if you have an element node then nodeValue is defined as
null. It is _not_ the text content of the element. If you want that then
you need the text property for MSXML or textContent for Firefox/Mozilla or
Opera 9.
And if you script XML on the web then be aware that the different parsers
your script will encounter might treat white space different, for instance
Mozilla will have text nodes with white space between element nodes. So a
script looking for an element node with e.g. childNodes[certainIndex]
might find an element node with one parser (e.g. MSXML) but a text node
with another parser (e.g. Mozilla). Thus if you are looking for element
child nodes then if you loop through childNodes or index it check the
nodeType, or better yet don't use childNodes but rather XPath (e.g.
selectSingleNode/selectNodes with MSXML, DOM Level 3 XPath API with
Mozilla and with Opera 9) to look for the child elements.


Client-side scripting questions are better asked in comp.lang.javascript
or if they relate to XML in comp.text.xml. The Microsoft server has
microsoft.public.xml for instance and various JScript scripting groups.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Sep 18 '06 #3

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

Similar topics

33
by: Darren Dale | last post by:
I love the language. I love the community. My only complaint is that Python for Windows is built with Visual Studio. It is too difficult to build python, or a module, from source. This is what...
0
by: lmckaha | last post by:
Hi, Mysql version: 3.23.49 Solaris version: 2.7 gcc compiler version: 2.95.2 Python : 2.2.2 I'm evaluating the C and C++ API to decide which one to bye but I have many troubles.
3
by: Mr. B | last post by:
GRRRR... I've run across a situation in which I have NO solution. Hopefully there is one. VB.net. It's rather simple. I've a ComboBox that get's populated via a Database. And I pre-select...
4
by: jernej goricki | last post by:
Hy I'm trying to edit a XSLT document, just like I'm editing a XML document : (Im trying to make a new xsl:template tag here ) Dim myXml As New XmlDocument()...
4
by: Edwin G. Castro | last post by:
I want to start a process from a C# application. I also want to redirect standard error to standard output so that I can read output from both streams just like I could from a command line. In...
0
by: Stefan Slapeta | last post by:
Hi all, I've experienced some troubles with message tables and wanted to know if anybody knows a solution for one of them: - If I translate my .mc file into a Unicode .bin file, some of the...
0
by: D'ALMEIDA Jorge | last post by:
Well i'm trying to get the icon of the visibles windows. i'm using: EnumWindows, IsWindowVisible, and SendMessage with the "WM_GETICON" parameter sometimes then SendMessage function return...
0
by: Michal | last post by:
I have troubles with instaling .Net Framework 2.0 (Beta 2 - 2.0.50215). The main instalation went just fine, troubles begin with my attemt to run aspnet_regiss.exe -i. Asp.Net is instaled into IIS...
0
by: JohnIdol | last post by:
VC++6 to VC++2003 - linking troubles -------------------------------------------------------------------------------- Hi All, I successfully ported an application from VC++6 to VS2003. Solved...
1
by: Pegasus | last post by:
Good morning, I'm Filippo Battaglia. We're porting Apache STDCXX under Nanodesktop. We are trying to make nd compatible also with C++ and not only with C. Unfortunately, we're finding different...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.