By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,460 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,460 IT Pros & Developers. It's quick & easy.

Invalid Name Character

P: n/a
Hi All,

I am facing an issue in the XmlTextWriter class in the dotnet 2.0.

This is the sample code

Actual XML is like this

<Name>詳細仕様に</Name>

code:

strvalue = "詳細仕様に"

public override void WriteString(string strValue)
{
int intPstn;

if(strValue.IndexOf("&") != -1)
{
intPstn = 0;

foreach(Match entMatch in rxEnt.Matches(strValue))
{
base.WriteString(strValue.Substring(intPstn, entMatch.Index - intPstn));

try
{
base.WriteEntityRef(entMatch.Value);
}
catch
{
base.WriteString(entMatch.Value);
}

intPstn = entMatch.Index + entMatch.Length;
}

base.WriteString(strValue.Substring(intPstn));
}
else
base.WriteString(strValue);
}
Here the base class is XmlTextWriter.

I am getting an error in base.WriteEntityRef as "Invalid name character in
&#x8A73" and please let me know how to resolve it.

Regards,
Vinod

Jul 10 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Vinod,

You need to give us some more information. There is nothing stopping you
from writing the Japanese (or Chinese?) text as it is to an xml file,
provided you use a proper encoding for it. You seem to check for existance
of converted characters. What are you using as Regex pattern (value of
rxEnt)? How do you end up with a &x string from "詳細仕様に"?

--
Happy Coding!
Morten Wennevik [C# MVP]
"Vinod" wrote:
Hi All,

I am facing an issue in the XmlTextWriter class in the dotnet 2.0.

This is the sample code

Actual XML is like this

<Name>詳細仕様に</Name>

code:

strvalue = "詳細仕様に"

public override void WriteString(string strValue)
{
int intPstn;

if(strValue.IndexOf("&") != -1)
{
intPstn = 0;

foreach(Match entMatch in rxEnt.Matches(strValue))
{
base.WriteString(strValue.Substring(intPstn, entMatch.Index - intPstn));

try
{
base.WriteEntityRef(entMatch.Value);
}
catch
{
base.WriteString(entMatch.Value);
}

intPstn = entMatch.Index + entMatch.Length;
}

base.WriteString(strValue.Substring(intPstn));
}
else
base.WriteString(strValue);
}
Here the base class is XmlTextWriter.

I am getting an error in base.WriteEntityRef as "Invalid name character in
&#x8A73" and please let me know how to resolve it.

Regards,
Vinod
Jul 11 '08 #2

P: n/a
Thanks Morten for your quick reply.

actually i am passing the value &#x8A73 &#x7D30 &#x4ED5 &#x69D8 &#x306B and
when it reads the value in writeentityref, it is causing the invalid name
character.

i am using Japanese characters and when i save the characters in the XML
(encoding ISO-8859-1) and it saves the values &#x8A73 &#x7D30 etc (each
value ends with semicolon). then i open the saved file and read the entity
one by one. the writeEntityRef fails to read the entity for Japanese
characters.
When i use the English text and writeEntityref reads the entity value and
works fine.

any other pointers would be appreciated.

Thanks,
Vinod

"Morten Wennevik [C# MVP]" wrote:
Hi Vinod,

You need to give us some more information. There is nothing stopping you
from writing the Japanese (or Chinese?) text as it is to an xml file,
provided you use a proper encoding for it. You seem to check for existance
of converted characters. What are you using as Regex pattern (value of
rxEnt)? How do you end up with a &x string from "詳細仕様に"?

--
Happy Coding!
Morten Wennevik [C# MVP]
"Vinod" wrote:
Hi All,

I am facing an issue in the XmlTextWriter class in the dotnet 2.0.

This is the sample code

Actual XML is like this

<Name>詳細仕様に</Name>

code:

strvalue = "詳細仕様に"

public override void WriteString(string strValue)
{
int intPstn;

if(strValue.IndexOf("&") != -1)
{
intPstn = 0;

foreach(Match entMatch in rxEnt.Matches(strValue))
{
base.WriteString(strValue.Substring(intPstn, entMatch.Index - intPstn));

try
{
base.WriteEntityRef(entMatch.Value);
}
catch
{
base.WriteString(entMatch.Value);
}

intPstn = entMatch.Index + entMatch.Length;
}

base.WriteString(strValue.Substring(intPstn));
}
else
base.WriteString(strValue);
}
Here the base class is XmlTextWriter.

I am getting an error in base.WriteEntityRef as "Invalid name character in
&#x8A73" and please let me know how to resolve it.

Regards,
Vinod
Jul 11 '08 #3

P: n/a
Hi Vinod,

What Regex pattern are you matching against? Your code uses an integer
value intPstn which you set at the end of each foreach loop, and you use this
value when the loop ends, but the integer would then only contain the
calculated value from the very last loop. Is this by design? It would
always be the index of the last value + the length of the last value.

--
Happy Coding!
Morten Wennevik [C# MVP]
"Vinod" wrote:
Thanks Morten for your quick reply.

actually i am passing the value &#x8A73 &#x7D30 &#x4ED5 &#x69D8 &#x306B and
when it reads the value in writeentityref, it is causing the invalid name
character.

i am using Japanese characters and when i save the characters in the XML
(encoding ISO-8859-1) and it saves the values &#x8A73 &#x7D30 etc (each
value ends with semicolon). then i open the saved file and read the entity
one by one. the writeEntityRef fails to read the entity for Japanese
characters.
When i use the English text and writeEntityref reads the entity value and
works fine.

any other pointers would be appreciated.

Thanks,
Vinod

"Morten Wennevik [C# MVP]" wrote:
Hi Vinod,

You need to give us some more information. There is nothing stopping you
from writing the Japanese (or Chinese?) text as it is to an xml file,
provided you use a proper encoding for it. You seem to check for existance
of converted characters. What are you using as Regex pattern (value of
rxEnt)? How do you end up with a &x string from "詳細仕様に"?

--
Happy Coding!
Morten Wennevik [C# MVP]
"Vinod" wrote:
Hi All,
>
I am facing an issue in the XmlTextWriter class in the dotnet 2.0.
>
This is the sample code
>
Actual XML is like this
>
<Name>詳細仕様に</Name>
>
code:
>
strvalue = "詳細仕様に"
>
public override void WriteString(string strValue)
{
int intPstn;
>
if(strValue.IndexOf("&") != -1)
{
intPstn = 0;
>
foreach(Match entMatch in rxEnt.Matches(strValue))
{
base.WriteString(strValue.Substring(intPstn, entMatch.Index - intPstn));
>
try
{
base.WriteEntityRef(entMatch.Value);
}
catch
{
base.WriteString(entMatch.Value);
}
>
intPstn = entMatch.Index + entMatch.Length;
}
>
base.WriteString(strValue.Substring(intPstn));
}
else
base.WriteString(strValue);
}
>
>
Here the base class is XmlTextWriter.
>
I am getting an error in base.WriteEntityRef as "Invalid name character in
&#x8A73" and please let me know how to resolve it.
>
Regards,
Vinod
>
Jul 12 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.