开发者

Server tags leave empty lines on xml content

开发者 https://www.devze.com 2023-04-12 22:33 出处:网络
I\'m developing an ASP.net application which outputs xml content in my aspx files. This application works sort of like a RSS feeder.

I'm developing an ASP.net application which outputs xml content in my aspx files. This application works sort of like a RSS feeder. One thing I have noticed which is quite bothering me is that lines containing server code will output an empty line in the fina开发者_如何学运维l xml content, for example:

<?xml version="1.0" encoding="utf-8" ?>
<foo>
    <tagOne>
        <% If(something) Then %>
            <myText>something</myText>
        <% End If %>
    </tagOne>
</foo>

If something is true, this will output the following:

<?xml version="1.0" encoding="utf-8" ?>
<foo>
    <tagOne>

            <myText>something</myText>

    </tagOne>
</foo>

How do I get rid of these empty lines without making the code one line only?

By creating only a single line I am making it rather difficult to edit in the future and some of these files contain 2000 or more lines of code which in a single line would be horrible to edit and maintain.


The server code seems to preserve the whitespace between XML tags. I'm not familiar with ASP but I've understood that the whitespace right after <% and right before %> is insignificant. Assuming that the whitespace inside the ASP "tags" is not preserved, you should be able to get rid of the extra whitespace and still preserve the indentation/formatting in your server code if you simply move the <% and/or %> markers so that the indentation is effectively inside the ASP command.

<?xml version="1.0" encoding="utf-8" ?>
<foo>
    <tagOne><% 
        If(something) Then %>
            <myText>something</myText><%
        End If %>
    </tagOne>
</foo>


I don't really know if this solves but give it a try;

<?xml version="1.0" encoding="utf-8" ?>
<foo>
    <tagOne>
    <% If(something) Then %><myText>something</myText><% End If %>
    </tagOne>
</foo>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号