Another xml Question
Another xml Question
(OP)
I am trying to produce this line of code using XmlTextwriter
<item>
<question>Who was named Player of the Match for the first Test in the 2019 Ashes series?</question>
<answer>Nathan Lyon</answer>
<answer correct="true">Steve Smith</answer>
<answer>Matthew Wade</answer>
<answer>Pat Cummins</answer>
</item>
I am having a problem with this line <answer correct="true">Steve Smith</answer>
eg....
writer.WriteStartElement("answer")
writer.WriteAttributeString("correct", "true") etc.....
No success !@!@!@!@
Appreciate any help
Regards Robert
<item>
<question>Who was named Player of the Match for the first Test in the 2019 Ashes series?</question>
<answer>Nathan Lyon</answer>
<answer correct="true">Steve Smith</answer>
<answer>Matthew Wade</answer>
<answer>Pat Cummins</answer>
</item>
I am having a problem with this line <answer correct="true">Steve Smith</answer>
eg....
writer.WriteStartElement("answer")
writer.WriteAttributeString("correct", "true") etc.....
No success !@!@!@!@
Appreciate any help
Regards Robert
RE: Another xml Question
Could you please elaborate?
What is the outcome, and what exactly does "etc....." do?
Best
MakeitSo
"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
RE: Another xml Question
All I am asking is how to get the following working
I have the program working BUT all the xml text is manually coded by me
I am not using any xml functions. eg xmltextwriter etc
eg
spd = Split(spt(LL + 1), ") ")
TheL = spd(1)
If xyz = TheL Then PrintLine(2, "<answer correct=" & Chr(34) & "true" & Chr(34) & ">" & TheL & "</answer>")
If xyz <> TheL Then PrintLine(2, "<answer>" & TheL & "</answer>")
I am trying to use the .net functions to create the same xml file
rather than doing longhand code
There are 5 quizzes in each xml file The following is the 1st of 5
I am trying to use xmltextwriter to create the following
<quiz number="1" question-label="number" answer-label="letter">
<items>
<item>
<question>Who was named Player of the Match for the first Test in the 2019 Ashes series?</question>
<answer>Nathan Lyon</answer>
<answer correct="true">Steve Smith</answer>
<answer>Matthew Wade</answer>
<answer>Pat Cummins</answer>
</item>
<item>
<question>Michael Collins is best known in association with which of the following events?</question>
<answer>Utegate political scandal in 2009</answer>
<answer>Discovery of penicillin</answer>
<answer>Assassination of John F. Kennedy</answer>
<answer correct="true">1969 Apollo 11 moon landing</answer>
</item>
</items>
</quiz>
I hope I am not asking too much, but really would appreciate the help
Regards Robert
RE: Another xml Question
The writing of the xml itself is pretty straightforward. If the node will have child nodes (attributes are also children), use WriteStartElement.
If you use WriteAttributeString, this applies to the previously written node; i.e. WriteStartElement followed directly by WriteAttributeString will add an attribute to that element.
In order get a properly listing of the questions, I have created a class like this:
CODE
So each Question has a dictionary of answers, which are qualified as either true or false.
You can then create an instance of this class, populate it and write to xml. Here an example:
CODE
Hope this helps.
Best regards
MakeItSo
"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
RE: Another xml Question
Thankyou very much for explaining this different method of
creating xml
I will now look closer at this and try using this method.
Really appreciate the time you have given to helping me.
Don't know why, but it has taken me a while coming to grips with xml !!!!
Must be getting old.. (which I am !!)
Regards
Robert
RE: Another xml Question
Just wait until you need to handle namespaces...
Probably best to post in the respective language forums like forum732: C# (C sharp): Microsoft or forum1867: Visual Basic (Microsoft) VB.NET then...
"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.