Reading XML File, '<br>' gives 'Element' is not a valid node type

J

JB

I'm returning a string from an xml file and trying to do something
like the following.

<Getter>
return HtmlEncode(s_tring.Value.Replace("\n","<br>"));
</Getter>

to replace a new-line character with a html line break.
But the "<BR>" is giving me errors as indicated in the title.

presumable it is parsing the string and thinking <br> is the start of
a new field in the xml file.

How can I go about reformatting it to let it through?



<?xml version="1.0" encoding="utf-8" ?> - if that effects things at
all. xml isnt my expertise :)
 
V

vMike

JB said:
I'm returning a string from an xml file and trying to do something
like the following.

<Getter>
return HtmlEncode(s_tring.Value.Replace("\n","<br>"));
</Getter>

to replace a new-line character with a html line break.
But the "<BR>" is giving me errors as indicated in the title.

presumable it is parsing the string and thinking <br> is the start of
a new field in the xml file.

How can I go about reformatting it to let it through?



<?xml version="1.0" encoding="utf-8" ?> - if that effects things at
all. xml isnt my expertise :)


You might try
<Getter><![CDATA[return
HtmlEncode(s_tring.Value.Replace("\n","<br>"));]]></Getter>

vmike
 
J

JB

I'm returning a string from an xml file and trying to do something
like the following.
<Getter>
   return HtmlEncode(s_tring.Value.Replace("\n","<br>"));
</Getter>
to replace a new-line character with a html line break.
But the "<BR>" is giving me errors as indicated in the title.
presumable it is parsing the string and thinking <br> is the start of
a new field in the xml file.
How can I go about reformatting it to let it through?
<?xml version="1.0" encoding="utf-8" ?> - if that effects things at
all. xml isnt my expertise :)

You might try
<Getter><![CDATA[return
HtmlEncode(s_tring.Value.Replace("\n","<br>"));]]></Getter>

vmike

I tried "<br/>" and that gives me the same error as before.

using <![CDATA[ ....]]
gives me 'This is an unexpected token. The expected token is '['. Line
1006, position 18. '
The stack trace is next to useless, just says there is a problem
reading the xml.


It works spot on if dont have the <br> in there, for example I replace
'\n' with '^' and its all good, but that doesnt help me format the
string :)
 
V

vMike

I'm returning a string from an xml file and trying to do something
like the following.
<Getter>
return HtmlEncode(s_tring.Value.Replace("\n","<br>"));
</Getter>
to replace a new-line character with a html line break.
But the "<BR>" is giving me errors as indicated in the title.
presumable it is parsing the string and thinking <br> is the start of
a new field in the xml file.
How can I go about reformatting it to let it through?
<?xml version="1.0" encoding="utf-8" ?> - if that effects things at
all. xml isnt my expertise :)

You might try
<Getter><![CDATA[return
HtmlEncode(s_tring.Value.Replace("\n","<br>"));]]></Getter>

vmike

I tried "<br/>" and that gives me the same error as before.

using <![CDATA[ ....]]
gives me 'This is an unexpected token. The expected token is '['. Line
1006, position 18. '
The stack trace is next to useless, just says there is a problem
reading the xml.


It works spot on if dont have the <br> in there, for example I replace
'\n' with '^' and its all good, but that doesnt help me format the
string :)

Make sure you have the closing > for the the cdata function. I can
successfully open the xml file without error with a <br> in it using

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Getter><![CDATA[return
HtmlEncode(s_tring.Value.Replace("\n","<br>"));]]></Getter>


Mike
 
J

Juan T. Llibre

Try : <br />

Notice the space between the "r" and the slash.
i.e., <br/> is wrong, but <br /> is OK.

Also, make sure the <br /> has a pair closing tag.

Yes, I know that allegedly a paired closing tag not needed, but when dealing with .xsd files
I found out, the hard way, that .xml files will not display when the <br /> tags aren't paired.

Maybe it's the same when parsing.




I'm returning a string from an xml file and trying to do something
like the following.
<Getter>
return HtmlEncode(s_tring.Value.Replace("\n","<br>"));
</Getter>
to replace a new-line character with a html line break.
But the "<BR>" is giving me errors as indicated in the title.
presumable it is parsing the string and thinking <br> is the start of
a new field in the xml file.
How can I go about reformatting it to let it through?
<?xml version="1.0" encoding="utf-8" ?> - if that effects things at
all. xml isnt my expertise :)

You might try
<Getter><![CDATA[return
HtmlEncode(s_tring.Value.Replace("\n","<br>"));]]></Getter>

vmike

I tried "<br/>" and that gives me the same error as before.

using <![CDATA[ ....]]
gives me 'This is an unexpected token. The expected token is '['. Line
1006, position 18. '
The stack trace is next to useless, just says there is a problem
reading the xml.


It works spot on if dont have the <br> in there, for example I replace
'\n' with '^' and its all good, but that doesnt help me format the
string :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top