Connecting Tech Pros Worldwide Forums | Help | Site Map

Invalid Name character

Newbie
 
Join Date: Oct 2007
Posts: 7
#1: Jul 10 '08
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>&#x8A73;&#x7D30;&#x4ED5;&#x69D8;&#x306B;</Name>

code:

strvalue = "&#x8A73;&#x7D30;&#x4ED5;&#x69D8;&#x306B;"

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

Moderator
 
Join Date: Mar 2006
Posts: 1,103
#2: Jul 14 '08

re: Invalid Name character


See http://www.w3.org/TR/REC-xml/ particularly the section with NCName and NameChar

NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender

The particular character you're using is not valid for an element name.
Reply