Display xml content in jsp page
jsp, xml
Solution
Stop using scriptlets in your JSPs. Learn how to use the JSP EL and the JSTL.
Once that is done, use the JSTL `<c:out>` tag, which escapes special characters like `<`, `>`, `&`, `"` and `'` so that they appear correctly in the page and are not interpreted as incorrect HTML markup by the browser. Your code will simply become:
<body>
<c:out value="${schema != null ? schema : 'no schema found'}"/>
</body>
Problem
Below is the body of jsp page i am using: ``` <body> <% String schema=(String)request.getAttribute("schema"); if(schema!=null) { **out.println(schema);** } else out.println("no schema found"); %> </body> ``` "out.println();" is not displaying the xml content in browser. the content of shcmea is : ``` <?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> ``` Myconcern is how can i display the content of schema variable which is xml in my browser?