I am trying to read an xml file . But my files conatins special character like '&' , due to this symbol i am getting problem and unable to read xml file .
i am using following code :-
xml file :-
<?xml version='1.0' encoding='UTF-8' ?>
<Job>
<PrinterName>NPI4A37C7</PrinterName>
<PrinterIpAddress>192.168.35.100</PrinterIpAddress>
<PrinterModel number="Q7830A">HP LaserJet M5035 MFP</PrinterModel>
<PrinterSerialNumber>CN5XBDX803</PrinterSerialNumber>
<PrinterFormatterNumber>GXG014A</PrinterFormatterNumber>
<PrinterColorSupport>1</PrinterColorSupport>
<PrinterDuplexSupport>0</PrinterDuplexSupport>
<MibId>43</MibId>
<JobId>13092736-4135-7362-3092-130927362413</JobId>
<Size>30511</Size>
<TotalPages>1</TotalPages>
<Status>4</Status>
<JobName>Microsoft Wor&d - Copy</JobName>
<MachineName>PCA0040</MachineName>
<DomainName>sinarmasproperty.com</DomainName>
<UserName>MAYAWEHANTOUW</UserName>
<SubmittedDate>2011-06-28 15:07:56</SubmittedDate>
<PrintedId>13092736-4137-7362-3092-130927362413</PrintedId>
<Simplex>1</Simplex>
<Duplex>0</Duplex>
<GrayScale>1</GrayScale>
<Color>0</Color>
<Orientation>0</Orientation>
<Economode></Economode>
<MediaWidth>210.0</MediaWidth>
<MediaHeight>297.0</MediaHeight>
<MediaSize>a4</MediaSize>
<MediaType>2</MediaType><BlackDots>521</BlackDots>
<YellowDots>0</YellowDots>
<CyanDots>0</CyanDots>
<MagentaDots>0</MagentaDots>
<Finishing>0</Finishing>
<Language></Language>
<JobType>1</JobType>
<GeneratedBy>SecureJet-Track-EM</GeneratedBy><Sheet>1</Sheet>
</Job>
try
{
XDocument doc = XDocument.Load(filepath);
var query = from d in doc.Root.Descendants("Jobs") select d;
foreach (var q in query)
{
string name = q.Element("PrinterName").Value;
string ssn = q.Element("PrinterIpAddress").Value;
string address = q.Element("PrinterSerialNumber").Value;
}
}
catch(Exception ex)
{ }
Load function is giving the error . once i removed special character its working but how to read with special character as i can not remove any character in XML .