473,324 Members | 2,473 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,324 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 3447
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.