em************* *@fastmail.fm wrote:
I'm using XmlWriter and WriteAttributeS tring which flagged up the
problem!
It was letting through "text!" as an attribute name and only once the
resulting XMLDocument was loaded via the written-to Stream and then
validated against my schema did the error occur.
Is that .NET 2.0? It does report a "System.Argumen tException: Invalid
name character" for me.
Doesn't seem to do that with .NET 1.x.
>>So producing XML with correct names should not be a problem. And parsing
XML should report any name violations any way.
Does that help? Or where/when exactly do you need to check a name?
We are allowing users to define their own attributename value pairs
ultimately to be put into an XML document as attributes i.e.
attributename = "value". I want to be able to validate the string they
enter as the attributename once they enter it
That could be one in .NET 1.x with WriteName e.g. alike
static public bool IsXmlName (string nameToCheck) {
XmlTextWriter xmlWriter = new XmlTextWriter(n ew StringWriter()) ;
bool isXmlName = true;
try {
xmlWriter.Write Name(nameToChec k);
}
catch (ArgumentExcept ion e) {
isXmlName = false;
}
finally {
xmlWriter.Close ();
}
return isXmlName;
}
and if there's any of the
disallowed characters just replace them with _.
See what I mean? Thanks for responding so quickly - any ideas? I was
thinking I'd have to bundle the whole definition of what was valid into
a regular expression or something.
I don't think there is any API in .NET 1.x or .NET 2.0 that flags the
individual disallowed characters in an XML name and then offers to
replace them with some allowed character. In that case you will need to
write that character replacement routine yourself.
Regular expressions in the .NET framework support Unicode character
groups/blocks with e.g. \p{name} so that might help to write the regular
expression.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/