Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  83] [ 1]  / answers: 1 / hits: 17137  / 14 Years ago, sat, february 26, 2011, 12:00:00

I'd like to store a some HTML/XML markups in a javascript variable. The problem is that the text is relatively large. For example how can I store the following XML piece in a javascript variable?



    <QuestionForm xmlns=[the QuestionForm schema URL]>
<Overview>
<Title>Game 01523, X to play</Title>
<Text>
You are helping to decide the next move in a game of Tic-Tac-Toe. The board looks like this:
</Text>
<Binary>
<MimeType>
<Type>image</Type>
<SubType>gif</SubType>
</MimeType>
<DataURL>http://tictactoe.amazon.com/game/01523/board.gif</DataURL>
<AltText>The game board, with X to move.</AltText>
</Binary>
<Text>
Player X has the next move.
</Text>
</Overview>
<Question>
<QuestionIdentifier>nextmove</QuestionIdentifier>
<DisplayName>The Next Move</DisplayName>
<IsRequired>true</IsRequired>
<QuestionContent>
<Text>
What are the coordinates of the best move for player X in this game?
</Text>
</QuestionContent>
<AnswerSpecification>
<FreeTextAnswer>
<Constraints>
<Length minLength=2 maxLength=2 />
</Constraints>
<DefaultText>C1</DefaultText>
</FreeTextAnswer>
</AnswerSpecification>
</Question>
<Question>
<QuestionIdentifier>likelytowin</QuestionIdentifier>
<DisplayName>The Next Move</DisplayName>
<IsRequired>true</IsRequired>
<QuestionContent>
<Text>
How likely is it that player X will win this game?
</Text>
</QuestionContent>
<AnswerSpecification>
<SelectionAnswer>
<StyleSuggestion>radiobutton</StyleSuggestion>
<Selections>
<Selection>
<SelectionIdentifier>notlikely</SelectionIdentifier>
<Text>Not likely</Text>
</Selection>
<Selection>
<SelectionIdentifier>unsure</SelectionIdentifier>
<Text>It could go either way</Text>
</Selection>
<Selection>
<SelectionIdentifier>likely</SelectionIdentifier>
<Text>Likely</Text>
</Selection>
</Selections>
</SelectionAnswer>
</AnswerSpecification>
</Question>
</QuestionForm>

More From » jquery

 Answers
19
var string = (<r><![CDATA[

The text string goes here. Since this is a XML CDATA section,
stuff like <> work fine too, even if definitely invalid XML.

]]></r>).toString();

[#93566] Thursday, February 24, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaitlyn

Total Points: 421
Total Questions: 73
Total Answers: 100

Location: South Georgia
Member since Sat, Jul 25, 2020
4 Years ago
kaitlyn questions
Mon, Jan 10, 22, 00:00, 2 Years ago
Wed, Jun 2, 21, 00:00, 3 Years ago
Wed, Jan 20, 21, 00:00, 3 Years ago
Mon, Dec 2, 19, 00:00, 5 Years ago
;