简体   繁体   English

添加<br/>串入变量

[英]Add <br/> to string in variable

I want to show the XML schema on the browser page.我想在浏览器页面上显示 XML 模式。

I need to add breakline <br/> to string to show info.我需要将breakline <br/>添加到字符串以显示信息。

I tried like this:我试过这样:

<div>
    @XMLSchema
</div>
@code {

private string XMLSchema = "<?xml version='1.0'?>" +
        "<Employee>" +
            "<Employee>" +
                "<FirstName>First</FirstName>" +
                "<LastName>Second</LastName>" +
                "<ContactNo>1234567890</ContactNo>" +
                "<Email>email@xyz.com</Email>" +
                "<Address><br>" +
                    "<City>City</City>" +
                    "<Street>Street</Street>" +
                    "<StreetNr>1</StreetNr>" +
                    "<HouseNr>1</HouseNr>" +
                    "<Zip>01123</Zip>" +
                "</Address>" +
            "</Employee>" +
        "</Employees>";

} }

And this does not work.这是行不通的。 I know is like text and can't work.我知道就像文本一样,无法工作。 Another special has is don't work too.另一个特殊之处是不起作用。

在此处输入图片说明

Is there another way to paste an XML record with fields in "<>" in HTML?是否有另一种方法可以在 HTML 的“<>”中粘贴带有字段的 XML 记录?

I don't know how I can do this without adding another variable to any single record.我不知道如何在不向任何单个记录添加另一个变量的情况下做到这一点。 Someone can help me?有人可以帮助我吗?

There are several ways to solve this but the best would be to define the html structor in the html part of the razor file and reference to the variables instead of define it as a string.有几种方法可以解决这个问题,但最好的方法是在 razor 文件的 html 部分定义 html 结构体并引用变量,而不是将其定义为字符串。 To avaoid your '<' are rendered you need to escape them by &lt;?为了避免您的'<'被渲染,您需要通过&lt;? . . Same for other Special caracters.其他特殊角色也一样。 This is why your solution not work, the whole string is not rended by the html engine, include the <br> .这就是为什么您的解决方案不起作用,整个字符串没有被 html 引擎渲染,包括<br> But that is good because otherwise also <Address> and other xml-tags would be rendered.但这很好,因为否则也会呈现<Address>和其他 xml-tags。

<div>
&lt;?xml version=&#39;1.0&#39;?&gt;&quot; 
    &quot;&lt;Employee&gt;&quot; 
        &quot;&lt;Employee&gt;&quot; 
            &quot;&lt;FirstName&gt;First&lt;/FirstName&gt;&quot; 
            &quot;&lt;LastName&gt;Second&lt;/LastName&gt;&quot; 
            &quot;&lt;ContactNo&gt;1234567890&lt;/ContactNo&gt;&quot; 
            &quot;&lt;Email&gt;email@xyz.com&lt;/Email&gt;&quot; 
            &quot;&lt;Address&gt;<br>quot; 
                &quot;&lt;City&gt;City&lt;/City&gt;&quot; 
                &quot;&lt;Street&gt;Street&lt;/Street&gt;&quot; 
                &quot;&lt;StreetNr&gt;1&lt;/StreetNr&gt;&quot; 
                &quot;&lt;HouseNr&gt;1&lt;/HouseNr&gt;&quot; 
                &quot;&lt;Zip&gt;01123&lt;/Zip&gt;&quot; 
            &quot;&lt;/Address&gt;&quot; 
        &quot;&lt;/Employee&gt;&quot; 
    &quot;&lt;/Employees&gt;&quot;
</div>

I'm not pretty sure I think Code will work fine like this..我不太确定我认为代码会像这样正常工作..

<Employee><br/> +
            <Employee><br/> +
                <FirstName>"First"</FirstName><br/> +

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM