하지만 Chrome

여기에 이미지 설명 입력

Firefox의 오류 XML Parsing Error: junk after document element Location: https://letscreatecustomdomainname-dev-ed--sii.ap6.visual.force.com/apex/PackageXMLGenerator?core.apexpages.devmode.url=1&core.apexpages.request.devconsole=1 Line Number 1, Column 228:<?xml version="1.0" encoding="UTF-8"?><products><product><Name>Xbox One</Name><Code>XBO</Code></product><product><Name>PlayStation 4</Name><Code>PS4</Code></product><product><Name>WII</Name><Code>Wii</Code></product></products><script type="text/javascript"> SfdcApp.Visualforce.viewstate.ViewstateSender.sendViewstate("https://letscreatecustomdomainname-dev-ed.my.salesforce.com", "sii__PackageXMLGenerator"); </script> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^

일부 출력도 나오지만 모든 태그가 누락되었습니다. 디버그에 적절한 xml이 있습니다. 아래는 내 코드입니다. 이유가 무엇인지 안내해주세요.

Apex 클래스에서 XML 생성

public class PackageXMLGeneratorController { public Blob csvFileBody{get;set;} public string csvAsString{get;set;} public string xmlstring { get; set;} public PackageXMLGeneratorController(){ DOM.Document doc = new DOM.Document(); dom.XmlNode products = doc.createRootElement("products", null, null); dom.XmlNode body1= products.addChildElement("product", null, null); body1.addChildElement("Name", null, null).addTextNode("Xbox One"); body1.addChildElement("Code", null, null).addTextNode("XBO"); dom.XmlNode body2= products.addChildElement("product", null, null); body2.addChildElement("Name", null, null).addTextNode("PlayStation 4"); body2.addChildElement("Code", null, null).addTextNode("PS4"); dom.XmlNode body3= products.addChildElement("product", null, null); body3.addChildElement("Name", null, null).addTextNode("WII"); body3.addChildElement("Code", null, null).addTextNode("Wii"); xmlstring = doc.toXmlString(); System.debug("========>"+xmlstring); } public ApexPages.PageReference downloadXML( ) { return Page.PackageXMLDownload; } } 

VF 페이지

<apex:page controller="PackageXMLGeneratorController" contentType="text/xml;filename.xml"> <apex:outputText escape="false" value="{!xmlstring}" /> </apex:page> 

답변

작동하려면 맞습니다 , 여분의 줄에주의를 기울여야합니다 코드가 깨집니다. 조직에서 다음을 생성했습니다.

<apex:page controller="q203222" contentType="text/xml;myfile.xml" showHeader="false">{!content}</apex:page> 

public class q203222 { public String getContent() { Dom.Document d = new Dom.Document(); d.createRootElement("test",null,null); d.getRootElement().addChildElement("data",null,null); return d.toXmlString(); } } 

Apex를 사용하지 마세요. outputText이며 페이지에 두 줄을 넘지 않아야합니다. 구문 분석 중에 오류가 발생하지 않도록 기본적으로이 패턴과 동일해야합니다.

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다