在JSP页面中显示XML内容

noo*_*one 3 xml jsp

以下是我正在使用的jsp页面的主体:

<body>
    <%


     String schema=(String)request.getAttribute("schema");
    if(schema!=null)
    {


    **out.println(schema);**
    }
    else
    out.println("no schema found");

    %>
    </body>
Run Code Online (Sandbox Code Playgroud)

“ out.println();” 在浏览器中未显示xml内容。

shcmea的内容是:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://edd.att.com/cnmeddservice" targetNamespace="http://edd.att.com/cnmeddservice" elementFormDefault="qualified">
    <xsd:include schemaLocation="EDD_DataTypes.xsd"/>
    <xsd:include schemaLocation="EDD_Internal_DataTypes.xsd"/>
    <xsd:element name="RET_MAIL">
        <xsd:annotation>
            <xsd:documentation>Represents the eddbdsbatch request for RET_MAIL</xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="AccountNumber">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:maxLength value="15"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="cType">
                    <xsd:simpleType>
                        <xsd:restriction base="CtypeType">
                            <xsd:enumeration value="RET_MAIL"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="RequestId">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:integer">
                            <xsd:pattern value="[0-9]{1,9}"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="BillingId" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:maxLength value="12"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="BillingRegion" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:enumeration value="S"/>
                            <xsd:enumeration value="P"/>
                            <xsd:enumeration value="B"/>
                            <xsd:enumeration value="A"/>
                            <xsd:enumeration value="N"/>
                            <xsd:enumeration value="W"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="BillIndicator" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:enumeration value="LS"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="EmailAddress" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:maxLength value="75"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="AccountBalance" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="DecimalAmountType">
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="BillAmount" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="DecimalAmountType">
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="DateLastchecked" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:pattern value="((0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])/(19|20)\d\d) ((0[0-9]|1[0-9]|2[0-4]):([0-5][0-9]):([0-5][0-9]))"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="PaymentDueDate" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="DateType"/>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="ctn">
                    <xsd:simpleType>
                        <xsd:restriction base="ContactNumberType">
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="AlternateCTN" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:maxLength value="10"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="AltPhoneExtension" minOccurs="0">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:maxLength value="4"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
                <xsd:element name="CustomerType">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:string">
                            <xsd:enumeration value="R"/>
                            <xsd:enumeration value="B"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
            </xsd:sequence>
            <xsd:attribute name="clientIndicator" use="required">
                <xsd:simpleType>
                    <xsd:restriction base="ClientIndicatorType">
                        <xsd:enumeration value="Wireless_BDS"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:attribute>
            <xsd:attribute name="OverridePriorityString" use="optional">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:enumeration value="E"/>
                        <xsd:enumeration value="A"/>
                        <xsd:enumeration value="S"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:attribute>
            <xsd:attribute name="Languageid" use="optional">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:enumeration value="EN"/>
                        <xsd:enumeration value="ES"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:attribute>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)

Myconcern是如何在浏览器中显示架构变量xml的内容?

JB *_*zet 5

停止在JSP中使用脚本。了解如何使用JSP ELJSTL

一旦做到这一点,使用JSTL <c:out>标签,它像转义特殊字符<>&"'让他们正确地显示在页面上,并不会被解释为浏览器不正确的HTML标记。您的代码将变成:

<body>
    <c:out value="${schema != null ? schema : 'no schema found'}"/>
</body>
Run Code Online (Sandbox Code Playgroud)