服务器标记在 xml 内容上留下空行
我正在开发一个 ASP.net 应用程序,它在我的 aspx 文件中输出 xml 内容。 该应用程序的工作原理有点像 RSS feeder。 我注意到一件让我很困扰的事情是,包含服务器代码的行将在最终的 xml 内容中输出一个空行,例如:
<?xml version="1.0" encoding="utf-8" ?>
<foo>
<tagOne>
<% If(something) Then %>
<myText>something</myText>
<% End If %>
</tagOne>
</foo>
如果某件事是 true,这将输出以下内容:
<?xml version="1.0" encoding="utf-8" ?>
<foo>
<tagOne>
<myText>something</myText>
</tagOne>
</foo>
如何删除这些空行而不使代码只有一行?
通过仅创建一行,我将来编辑会变得相当困难,其中一些文件包含 2000 行或更多行代码,在一行中编辑和维护这些代码将非常困难。
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 final 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
服务器代码似乎保留了 XML 标记之间的空白。我不熟悉 ASP,但我知道
<%
之后和%>
之前的空格是无关紧要的。假设 ASP“标签”内的空格未被保留,那么您应该能够删除多余的空格并且仍然保留服务器代码中的缩进/格式,只要您简单地移动<%
和/或%>
标记,以便缩进有效地位于 ASP 命令内部。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.我真的不知道这是否能解决问题,但请尝试一下;
I don't really know if this solves but give it a try;