commit
4fca8c94a2
1 changed files with 12 additions and 3 deletions
|
|
@ -51,6 +51,9 @@ const
|
||||||
# Illegal characters
|
# Illegal characters
|
||||||
illegalChars = {'>', '<', '&', '"'}
|
illegalChars = {'>', '<', '&', '"'}
|
||||||
|
|
||||||
|
# standard xml: attribute names
|
||||||
|
# see https://www.w3.org/XML/1998/namespace
|
||||||
|
stdattrnames = ["lang", "space", "base", "id"]
|
||||||
|
|
||||||
type
|
type
|
||||||
Feature = tuple[name: string, version: string]
|
Feature = tuple[name: string, version: string]
|
||||||
|
|
@ -229,12 +232,15 @@ proc createAttributeNS*(doc: PDocument, namespaceURI: string, qualifiedName: str
|
||||||
raise newException(EInvalidCharacterErr, "Invalid character")
|
raise newException(EInvalidCharacterErr, "Invalid character")
|
||||||
# Exceptions
|
# Exceptions
|
||||||
if qualifiedName.contains(':'):
|
if qualifiedName.contains(':'):
|
||||||
|
let qfnamespaces = qualifiedName.toLower().split(':')
|
||||||
if isNil(namespaceURI):
|
if isNil(namespaceURI):
|
||||||
raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil")
|
raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil")
|
||||||
elif qualifiedName.split(':')[0].toLower() == "xml" and namespaceURI != "http://www.w3.org/XML/1998/namespace":
|
elif qfnamespaces[0] == "xml" and
|
||||||
|
namespaceURI != "http://www.w3.org/XML/1998/namespace" and
|
||||||
|
qfnamespaces[1] notin stdattrnames:
|
||||||
raise newException(ENamespaceErr,
|
raise newException(ENamespaceErr,
|
||||||
"When the namespace prefix is \"xml\" namespaceURI has to be \"http://www.w3.org/XML/1998/namespace\"")
|
"When the namespace prefix is \"xml\" namespaceURI has to be \"http://www.w3.org/XML/1998/namespace\"")
|
||||||
elif qualifiedName.split(':')[1].toLower() == "xmlns" and namespaceURI != "http://www.w3.org/2000/xmlns/":
|
elif qfnamespaces[1] == "xmlns" and namespaceURI != "http://www.w3.org/2000/xmlns/":
|
||||||
raise newException(ENamespaceErr,
|
raise newException(ENamespaceErr,
|
||||||
"When the namespace prefix is \"xmlns\" namespaceURI has to be \"http://www.w3.org/2000/xmlns/\"")
|
"When the namespace prefix is \"xmlns\" namespaceURI has to be \"http://www.w3.org/2000/xmlns/\"")
|
||||||
|
|
||||||
|
|
@ -305,9 +311,12 @@ proc createElement*(doc: PDocument, tagName: string): PElement =
|
||||||
proc createElementNS*(doc: PDocument, namespaceURI: string, qualifiedName: string): PElement =
|
proc createElementNS*(doc: PDocument, namespaceURI: string, qualifiedName: string): PElement =
|
||||||
## Creates an element of the given qualified name and namespace URI.
|
## Creates an element of the given qualified name and namespace URI.
|
||||||
if qualifiedName.contains(':'):
|
if qualifiedName.contains(':'):
|
||||||
|
let qfnamespaces = qualifiedName.toLower().split(':')
|
||||||
if isNil(namespaceURI):
|
if isNil(namespaceURI):
|
||||||
raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil")
|
raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil")
|
||||||
elif qualifiedName.split(':')[0].toLower() == "xml" and namespaceURI != "http://www.w3.org/XML/1998/namespace":
|
elif qfnamespaces[0] == "xml" and
|
||||||
|
namespaceURI != "http://www.w3.org/XML/1998/namespace" and
|
||||||
|
qfnamespaces[1] notin stdattrnames:
|
||||||
raise newException(ENamespaceErr,
|
raise newException(ENamespaceErr,
|
||||||
"When the namespace prefix is \"xml\" namespaceURI has to be \"http://www.w3.org/XML/1998/namespace\"")
|
"When the namespace prefix is \"xml\" namespaceURI has to be \"http://www.w3.org/XML/1998/namespace\"")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue