sa3q
asked on
when i try to read xml file in c# the unicode appear like ?????????? questions mark how can i solve it
hello,
when i try to use the code below to change & to --> &
i found that the Unicode that included in the XML file appear like question mark ?????????
how can i solve it ???
thank you
when i try to use the code below to change & to --> &
i found that the Unicode that included in the XML file appear like question mark ?????????
how can i solve it ???
thank you
XmlDocument doc = new XmlDocument ();
string s = System.Text.RegularExpressions.Regex.Replace (System.IO.File.ReadAllText (@"D:\x.xml").ToString (), "&", "&");
doc.LoadXml (s);
Hi,
I tried the above it works, I mean it replaces perfectly, Can you post you xml file?
Thanks,
Arun
I tried the above it works, I mean it replaces perfectly, Can you post you xml file?
Thanks,
Arun
ASKER
i know that it make replace but after i do replace i want to read the tags and if the attributes have any non English word it appear to me like that (?????)
thats why I suggested HTMLEncode
ASKER
pradyahuja:>>
my code run on application not on web
my code run on application not on web
ASKER
Server
not defined
not defined
try
HttpUtility.HtmlEncode
HttpUtility.HtmlEncode
ASKER
what name space that have this class
System.Web
Hi,
Post you xml file.
Thanks,
Arun.
Post you xml file.
Thanks,
Arun.
ASKER
this what happened
Capture.PNG
Capture.PNG
Hi,
If its possible provide your original xml file. [If you have any importantant info, modify the content and post it]
Thanks,
Arun
If its possible provide your original xml file. [If you have any importantant info, modify the content and post it]
Thanks,
Arun
ASKER
this is sample xml file
the data in arabic language not appear but appear like ???????
when i use the dom to load the xml
----------------------
XmlDocument dom = new XmlDocument();
string s = System.Text.RegularExpress ions.Regex .Replace(S ystem.IO.F ile.ReadAl lText(text Box1.Text) .ToString( ), "&", "&");
dom.LoadXml(s);
the data in arabic language not appear but appear like ???????
when i use the dom to load the xml
----------------------
XmlDocument dom = new XmlDocument();
string s = System.Text.RegularExpress
dom.LoadXml(s);
<?xml version="1.0" encoding="Windows-1256"?>
<directory name="c:">
<directory name="c:\k">
<file name="¿¿¿¿¿¿.txt" size="544"/>
<file name="¿¿¿¿¿¿.txt" size="544"/>
<file name="¿¿¿¿¿¿.txt" size="544"/>
<file name="$&ITIDIXW" size="544"/>
<file name="$IZ7AR8A&df.exe" size="544"/>
</directory>
</directory>
ASKER
this is the original file for the xml file because their problems when i attached the code
orignial.xml
orignial.xml
did u try
System.Web.HttpUtility.Htm lEncode
System.Web.HttpUtility.Htm
ASKER
when i use
dom.LoadXml(xml_String );
the arabic language appear ???????
but when i use
//dom.Load(@"c:\\file.xml" );
the arabic language appear ok
dom.LoadXml(xml_String );
the arabic language appear ???????
but when i use
//dom.Load(@"c:\\file.xml"
the arabic language appear ok
ASKER
i tried System.Web.HttpUtility.Htm lEncode
but HttpUtility.HtmlEncode
not found in this name space
but HttpUtility.HtmlEncode
not found in this name space
did u try this code?
XmlDocument doc = new XmlDocument ();
string s =System.Web.HttpUtility.HtmlEncode(System.IO.File.ReadAllText (@"D:\x.xml").ToString ());
doc.LoadXml (s);
ASKER
i used this code before and the name space for the HttpUtility not found
ASKER
to find where is the problem i used this function to make replace of "&" to "&" in original.xml file
and i found that this function (System.Text.RegularExpres sions.Rege x.Replace( content, searchText, replaceText );) destroy any Unicode letters in the file
how can i make replace with out damage unicode characters
and i found that this function (System.Text.RegularExpres
how can i make replace with out damage unicode characters
static public void ReplaceInFile( string filePath, string searchText, string replaceText )
{
StreamReader reader = new StreamReader( filePath );
string content = reader.ReadToEnd();
reader.Close();
content = System.Text.RegularExpressions.Regex.Replace( content, searchText, replaceText );
StreamWriter writer = new StreamWriter( filePath );
writer.Write( content );
writer.Close();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks very much best solution i have seen
Open in new window