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

Discussion in 'ASP .Net' started by JB, Apr 8, 2008.

  1. JB

    JB Guest

    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 :)
     
    JB, Apr 8, 2008
    #1
    1. Advertising

  2. JB

    vMike Guest

    "JB" <> wrote in message
    news:...
    > 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
     
    vMike, Apr 8, 2008
    #2
    1. Advertising

  3. JB

    JB Guest

    On 8 Apr, 16:09, "vMike" <> wrote:
    > "JB" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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 :)
     
    JB, Apr 8, 2008
    #3
  4. JB

    vMike Guest

    "JB" <> wrote in message
    news:...
    On 8 Apr, 16:09, "vMike" <> wrote:
    > "JB" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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
     
    vMike, Apr 8, 2008
    #4
  5. 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.



    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ======================================
    "JB" <> wrote in message news:...
    On 8 Apr, 16:09, "vMike" <> wrote:
    > "JB" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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 :)
     
    Juan T. Llibre, Apr 8, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,617
  2. Chishun Kwong
    Replies:
    0
    Views:
    432
    Chishun Kwong
    Mar 3, 2005
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,477
    Dimitre Novatchev
    Aug 24, 2006
  4. Martin Honnen

    Re: Reading XML Node-by-Node

    Martin Honnen, Nov 12, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    399
    Martin Honnen
    Nov 12, 2008
  5. Replies:
    0
    Views:
    196
Loading...

Share This Page