473,376 Members | 1,067 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,376 software developers and data experts.

how to read XML by using GetElementsByTagName

need help here.

here is my XML file.

<kelvin>
<module assignment="1" questionno.="0">
<question>asd</question>
<choice1>1</choice1>
<choice2>2</choice2>
<choice3>3</choice3>
<choice4>4</choice4>
<correctchoice>Choice 2</correctchoice>
</module>
<module assignment="1" questionno.="1">
<question>asdasd</question>
<choice1>11</choice1>
<choice2>22</choice2>
<choice3>33</choice3>
<choice4>44</choice4>
<correctchoice>Choice 2</correctchoice>
</module>
<module assignment="1" questionno.="2">
<question>dsfsdf</question>
<choice1>111</choice1>
<choice2>222</choice2>
<choice3>333</choice3>
<choice4>444</choice4>
<correctchoice>Choice 3</correctchoice>
</module>
</kelvin>


display question at question label.
display Choice1 at choice1 label.
display Choice2 at choice2 label.

i've tried, but my label display everyting in that particular element.

please help me.
Thank You.
Sep 23 '08 #1
11 3449
Dormilich
8,658 Expert Mod 8TB
do you use DOM or XSLT to do the transformation?

regards
Sep 23 '08 #2
XSLT for the transformation.
Sep 23 '08 #3
Dormilich
8,658 Expert Mod 8TB
what shall the output file look like?
Sep 23 '08 #4
just display out on the Label, Questions, Choices.
just display Selective Question only and not all Question under the element <question>. Or Choices <choice1>.

something like that.
Sep 23 '08 #5
Dormilich
8,658 Expert Mod 8TB
the text of <question> you can get with //question/text(). same goes for <choiceX> (though I'd rename it to <choice no="X">, because you can then loop over <choice>). a special <question> you get with //question/text()[ancestor::module/@questionno. = 'X']

regards
Sep 23 '08 #6
jkmyoung
2,057 Expert 2GB
Could we see the code you're using to get choice1?
Sep 23 '08 #7
XmlNodeList Choice1 = doc.GetElementsByTagName("choice1");
foreach (XmlNode Choice in Choice1)
{
AnsLabel1.Text += Choice.ChildNodes[0].Value;
}

the code for choice and Question is similar.

please help.
Sep 24 '08 #8
Dormilich
8,658 Expert Mod 8TB
actually, this is DOM (Javascript maybe). XSLT is totally different. for XSLT I've given you (one possibility of) the XPath expressions you'll need for XSL. although I have no idea yet, how you will build it into HTML (a script?).

regards
Sep 24 '08 #9
to: Dormilich ,
mind show me some example how to do the xslt code.

cause im really lost here.
thanks alot.
Sep 25 '08 #10
this is my.
MCQ.xslt.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="MCQ.xsl"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>Student Assignment</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>


<xsl:template match="question">
<b> Question: </b><xsl:value-of select="."/>
<xsl:value-of select="."/>
<br />
</xsl:template>

<xsl:template match="choice1">
<b> Choice 1: </b><xsl:value-of select="."/>
<br />
</xsl:template>

<xsl:template match="choice2">
<b> Choice 2: </b><xsl:value-of select="."/>
<br />
</xsl:template>

<xsl:template match="choice3">
<b> Choice 3: </b><xsl:value-of select="."/>
<br />
</xsl:template>

<xsl:template match="choice4">
<b> Choice 4: </b><xsl:value-of select="."/>
<br />
</xsl:template>

<xsl:template match="correctchoice">
<b> Correct Choice: </b><xsl:value-of select="."/>
<br />
</xsl:template>

</xsl:stylesheet>

i hope You guys can help.
=)
Sep 25 '08 #11
Dormilich
8,658 Expert Mod 8TB
er, it looks fine. this is, what your code displays:

Student Assignment

Question: asd
Choice 1: 1
Choice 2: 2
Choice 3: 3
Choice 4: 4
Correct Choice: Choice 2
Question: asdasd
Choice 1: 11
Choice 2: 22
Choice 3: 33
Choice 4: 44
Correct Choice: Choice 2
Question: dsfsdf
Choice 1: 111
Choice 2: 222
Choice 3: 333
Choice 4: 444
Correct Choice: Choice 3

unless I totally misunderstood your problem

regards
Sep 29 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andrew Poulos | last post by:
If I do something like the following snippet in JS: xFile = "test.xml"; xDoc = document.implementation.createDocument("", "theXdoc", null); xDoc.load(xFile); // there's a pause here then ...
7
by: adam | last post by:
i'm working on a portion of a CMS that allows content-admins to browse a product list, and add individual products into the taxonomy by clicking checkboxes next to categories they might belong in....
7
by: SQLScott | last post by:
I have a Web Service in which I am trying to pass an XMLDocument as a parameter to one of the methods. I would like to use the XMLTextReader to read the XML but I am getting the following error: ...
2
by: Scamjunk | last post by:
I have been desperately looking for a treeview-type solution for my problem for the past three weeks and have been greatly unsuccessful. I am totally new to the world of XSLT and I *don't know*...
0
by: dphill | last post by:
Hello all I am a beginner .Net programmer so please forgive my ignorance. In brief, I am trying to read from xml file stored in a SQL database table’s field. This is what I used to create...
6
by: | last post by:
Hi, I'm steel trying to read and update my XML file with Visual Basic Express but i am unable to find the right way to read my xml file and update it if neccessary... Here is my problem :...
9
by: retrofill | last post by:
Hey i've got a problem with printing out an XML document: XML doc: http://www.deniseburrows.pwp.blueyonder.co.uk/javascript/data.xml If i remove the comments from the lines that add the...
5
by: subbulakshmi | last post by:
hi how to read data from XMLDocument by using Javascript. i got coding from internet. but its not read data. help me its in JavaScript ----------------------- //server return XML...
4
by: Michael Munch | last post by:
Hi I want to read the value of af text-field, create dynamic, in a form. Se below a small test-site to do that (but readning fails): I use the function Test_Read for reading the value from the...
0
by: sujata321 | last post by:
Hi, I need to update an XML file using ASP and javascript/vbscript. But this is not working.It is showing the error document is not defined in the line ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.