You need to sign in to do that
Don't have an account?
melmoussaoui
Creating an XML with Xmlstreamwriter
Hello, I'm new to apex and salesforce world and I'm trying to create an XML file using Xmlstreamwriter which should look like this :
<?XML version="1.0" encoding="utf-8"?> <SERVICE version="1.0"> <CLIENT email="xx.xx@xx.xx"> <BASIC_FIELDS id="1"> <ADDRESS_LINE_1 id="2" >24 rue de rocher</ADDRESS_LINE_1> <CITY id="3" >Paris</CITY> </BASIC_FIELDS> </CLIENT> </SERVICE>
but when I try this code :
public String getxmlRes() { Xmlstreamwriter xmlW = new Xmlstreamwriter(); xmlW.writeStartDocument('utf-8','1.0'); xmlW.writeStartElement('SERVICE', 'version', '"1.0"'); xmlW.writeStartElement(null,'CLIENT email= xxx@xx.com',null); xmlW.writeStartElement(null,'BASIC_FIELDS id="1"',null); xmlW.writeAttribute(null, null, 'ADRESS_LINE id="2"', '24 rue de rocher'); xmlW.writeAttribute(null, null,'CITY id="3"', 'Paris'); xmlW.writeEndElement(); xmlW.writeEndElement(); xmlW.writeEndElement(); xmlW.writeEndDocument(); String xmlStringxmlRes = xmlW.getXmlString(); System.debug('The XML :'+xmlW.getXmlString()); xmlW.close(); return xmlStringxmlRes; }
instead I get this :
<?xml version="1.0" encoding="utf-8"?> <SERVICE:version> <CLIENT email= xxx@xx.com> <BASIC_FIELDS id="1" ADRESS_LINE id="2"="24 rue de rocher" CITY id="3"="Paris"> </BASIC_FIELDS id="1"> </CLIENT email= xxx@xx.com> </SERVICE:version>
i hope someone could help me!
thanks
Give this a try:
Thank you, that what i did and it works !
Hi,
Excuse if I re-up this old topic, but I have to ask:
How do you apply this apex code into a button to create the xml file?
Thanks for your example. It worked perfect.
Do you have any idea on how to post generated xml file to Internal network(specified location)?
I believe we can implement this using Http post method...but what would be the format for setendpointurl?
Thanks in Advance.............
can you please send me code or give me an idea how to do that.
Does anyone aware of any tool which will provide the code from xml to Xmlstreamwriter .. thanks