MCPcopy Create free account
hub / github.com/denoland/std / validateQName

Function validateQName

xml/_common.ts:420–441  ·  view source on GitHub ↗
(name: string, colonIndex: number)

Source from the content-addressed store, hash-verified

418 * @returns Error message if invalid, null if valid.
419 */
420export function validateQName(name: string, colonIndex: number): string | null {
421 if (colonIndex === -1) {
422 return null; // No colon means valid NCName (already validated by name char rules)
423 }
424
425 // Colon at start (:foo) - invalid
426 if (colonIndex === 0) {
427 return "QName cannot start with ':'";
428 }
429
430 // Colon at end (foo:) - invalid
431 if (colonIndex === name.length - 1) {
432 return "QName cannot end with ':'";
433 }
434
435 // Multiple colons (a:b:c) - invalid
436 if (name.indexOf(":", colonIndex + 1) !== -1) {
437 return "QName cannot contain multiple ':'";
438 }
439
440 return null; // Valid QName
441}
442
443/**
444 * Validates a namespace binding (xmlns or xmlns:prefix attribute).

Callers 4

_common_test.tsFile · 0.90
parseSyncFunction · 0.90
onStartTagOpenMethod · 0.90
onAttributeMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected