在 XML 数据中动态插入换行符
"<log date=\"" + date +
"\" trnType=\"" +
"\" accountType=\"" + XMLIllegalCharacterEncoder.encodedString(accountType) +
"\" ***accountId=\"" + accountBSB + "\r\n" + accountId*** +
"\" groupingID=\"" + groupingId +
"\"/>"
我正在尝试在动态创建的 XML 数据中插入换行符。 我尝试了几个选项,但没有任何效果可以在 XML 数据中插入换行符
在下面的代码中,
"\" ***accountId=\"" + accountBSB + "\r\n" + accountId*** +
尝试在 accountBSB 和 accountId 之间插入换行符
任何人都可以帮助我解决此问题
"<log date=\"" + date +
"\" trnType=\"" +
"\" accountType=\"" + XMLIllegalCharacterEncoder.encodedString(accountType) +
"\" ***accountId=\"" + accountBSB + "\r\n" + accountId*** +
"\" groupingID=\"" + groupingId +
"\"/>"
I am trying to insert an Line Break in the XML data which I am creating dynamically.
I have tried few options, but nothing worked to insert the line break inside the XML data
In the Below piece of Code,
"\" ***accountId=\"" + accountBSB + "\r\n" + accountId*** +
Trying to insert an Break between accountBSB and accountId
can any one help me the solutions with this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
,而不是
\r\n
。不过,我建议不要使用剪切粘贴技术来构建 XML。使用适当的工具,如 JDOM 或 DOM4J(如果您使用的是 java)
更新:
根据 XML 规范,属性值在传递给应用程序之前必须进行“规范化”(http://www.w3.org/TR /REC-xml/#AVNormalize)。简而言之,规范化过程将
\r\n
序列替换为单个空白字符。任何字符引用,例如都会被保留。因此,在您的情况下,如果您希望使用 XML 的应用程序实际看到换行符,则必须使用字符引用而不是文字回车符和换行符。
Instead of
\r\n
, try.
However, I would recommend against constructing XML using cut-n-paste techniques. Use a proper tool like JDOM or DOM4J (if you are using java)
UPDATE:
According to the XML specification, an attribute value must be "normalized" before it is passed to the application (http://www.w3.org/TR/REC-xml/#AVNormalize). Briefly, the normalization process replaces
\r\n
sequneces with a single white space character. Any character reference, such asis preserved. So, in your case, if you want an application consuming your XML to actually see the line break, you must use a character reference instead of literal carriage return and line feed.