Invalid Name Character

V

Vinod

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
 
M

Morten Wennevik [C# MVP]

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 "詳細仕様ã«"?
 
V

Vinod

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 said:
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 said:
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
 
M

Morten Wennevik [C# MVP]

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 said:
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 said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top