Member Avatar

> I have an xml document that looks like this: <OUTPUT version="2.0"> <RESPONSE> <LOAN_DATA loan_id="xxxx" loan_number="1111" loan_type="HE" status_code="OK"> <![CDATA[<MORTGAGE_LOAN xmlns="http://www.something.com/CLF" version="1.0"> <APPLICANTS> <APPLICANT is_declined="N" first_name="MARISOL" last_name="TESTCASE" m_initial="L" middle_name="L" ssn="000000001" > </APPLICANT> </APPLICANTS> </MORTGAGE_LOAN>]]> </LOAN_DATA> </RESPONSE> </OUTPUT> I can successfully read down to the CData section and can even access the CData section using the following: string cData = ""; XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(loanData); XmlNode node = xDoc.DocumentElement.SelectSingleNode(@"RESPONSE/LOAN_DATA"); XmlNode childNode = node.ChildNodes[0]; if (childNode is XmlCDataSection) { XmlCDataSection cdataSection = childNode as XmlCDataSection; cData = cdataSection.Value; } > cData now holds: <MORTGAGE_LOAN xmlns="http://www.something.com/CLF" version="1.0"> <APPLICANTS> <APPLICANT is_declined="N" first_name="MARISOL" last_name="TESTCASE" …

Member Avatar
0
15
Member Avatar

I'm trying to create an xml document without converting html entities but when I create and save the file with DOMDocument the < and > characters are converted to &lt; and &gt; so trying to wrap copy within <![CDATA[]]> is proving problematic. Example of my code below: // Initiate the XML $doc = new DOMDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $r = $doc->createElement("advertising"); $doc->appendChild($r); // <ad> $ad = $doc->createElement('ad'); // <TITLE> $title = $doc->createElement('TITLE'); $title->appendChild($doc->createTextNode('<![CDATA['.$v_title.']]>')); $ad->appendChild($title); // </ad> $r->appendChild($ad); // Save xml $doc->saveXML(); $doc->save('ads.xml'); Could anyone tell me how I prevent this?

Member Avatar
0
3

The End.