471,594 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

how to read XML by using GetElementsByTagName

need help here.

here is my XML file.

<module assignment="1" questionno.="0">
<correctchoice>Choice 2</correctchoice>
<module assignment="1" questionno.="1">
<correctchoice>Choice 2</correctchoice>
<module assignment="1" questionno.="2">
<correctchoice>Choice 3</correctchoice>

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 3317
8,656 Expert Mod 8TB
do you use DOM or XSLT to do the transformation?

Sep 23 '08 #2
XSLT for the transformation.
Sep 23 '08 #3
8,656 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
8,656 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']

Sep 23 '08 #6
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
8,656 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?).

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.

<?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="/">
<h2>Student Assignment</h2>

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

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

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

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

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

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


i hope You guys can help.
Sep 25 '08 #11
8,656 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

Sep 29 '08 #12

Post your reply

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

Similar topics

3 posts views Thread by Andrew Poulos | last post: by
2 posts views Thread by Scamjunk | last post: by
4 posts views Thread by Michael Munch | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.