Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
I have a data like this :-

<pre lang="text"><string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;DataCaptureSettings&gt;&lt;ModuleSettings&gt;&lt;capture_local_dir&gt;c:\&lt;/capture_local_dir&gt;&lt;capture_log_dir&gt;c:\log&lt;/capture_log_dir&gt;&lt;capture_log_level&gt;debug&lt;/capture_log_level&gt;&lt;capture_request_interval&gt;2&lt;/capture_request_interval&gt;&lt;capture_connection_interval&gt;2&lt;/capture_connection_interval&gt;&lt;smtp_server_name&gt;n1&lt;/smtp_server_name&gt;&lt;smtp_server_port&gt;80&lt;/smtp_server_port&gt;&lt;/ModuleSettings&gt;&lt;Machines&gt;&lt;Machine&gt;&lt;MachineId&gt;0022&lt;/MachineId&gt;&lt;AccountId&gt;1&lt;/AccountId&gt;&lt;location_code&gt;LOC_100&lt;/location_code&gt;&lt;Make&gt;Nipro&lt;/Make&gt;&lt;Model&gt;Model1&lt;/Model&gt;&lt;SerialNumber&gt;126649E&lt;/SerialNumber&gt;&lt;IpAddress&gt;10.10.10.10&lt;/IpAddress&gt;&lt;Port&gt;80&lt;/Port&gt;&lt;/Machine&gt;&lt;Machine&gt;&lt;MachineId&gt;3000&lt;/MachineId&gt;&lt;AccountId&gt;1&lt;/AccountId&gt;&lt;location_code&gt;LOC_100&lt;/location_code&gt;&lt;Make&gt;Make3&lt;/Make&gt;&lt;Model&gt;Model3&lt;/Model&gt;&lt;SerialNumber&gt;SN3&lt;/SerialNumber&gt;&lt;IpAddress&gt;30.30.30.30&lt;/IpAddress&gt;&lt;Port&gt;80&lt;/Port&gt;&lt;/Machine&gt;&lt;/Machines&gt;&lt;/DataCaptureSettings&gt;</string> </pre>

With some modification i want a data like this:-
Can anyone please tell what to do?


<pre lang="text"><?xml version="1.0" encoding="UTF-8"?><DataCaptureSesstings><ModuleSettings><account_id name="id">1</account_id><capture_local_dir>c:</capture_local_dir><capture_log_dir>c:log</capture_log_dir><capture_log_level>debug</capture_log_level><capture_request_interval>2</capture_request_interval><capture_connection_interval>2</capture_connection_interval><smtp_server_name>n1</smtp_server_name><smtp_server_port>80</smtp_server_port><smtp_email_sender>s1</smtp_email_sender><smtp_email_sender_password>p1</smtp_email_sender_password></ModuleSettings><MachineList><Machine><MachineId>0022</MachineId><Make>Make1</Make><Model>Model1</Model><SerialNumber>SN1</SerialNumber><IpAddress>10.10.10.10</IpAddress><Port>80</Port></Machine><Machine><MachineId>3000</MachineId><Make>Make3</Make><Model>Model3</Model><SerialNumber>SN3</SerialNumber><IpAddress>30.30.30.30</IpAddress><Port>80</Port></Machine></MachineList></DataCaptureSesstings> </pre>
Posted

1 solution

If the string does not contain other XML entities than those for reserved characters and no Unicode points, you may use the CStringT class to replace the entities by characters:
C++
CString ReplaceEntities(LPCTSTR lpszHtml)
{
    CString s(lpszHtml);
    s.Replace(_T("&gt;"), _T(">"));
    s.Replace(_T("&lt;"), _T("<"));
    s.Replace(_T("&quot;"), _T("\""));
    s.Replace(_T("&apos;"), _T("'"));
    s.Replace(_T("&amp;"), _T("&")); // Perform this replacement as the last one
    return s;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900