Browse Source
* First pass at adding Xml parsing support to js platform Likely still need to add tests and samples * Add JS to Parser Node and Element converter Mirrors native impl by returning empty strings when content is unavailable Moves MalformedXMLException out of native code, useful for common case. * Remove unneeded null checks in Parser Last commit handled null management * Add newlines for code linter * Fix namespaceUri bug Undo accidental capture of localName Also remove unneeded null check * Undo grade.properies change Had to disable webpack version number property to run sample * Clean up NodeImpl comments Corrected description * Make NodeList impl lazy Generates only when needed, serves cache aftercompose-tooling-223 v1.5.0-dev1036
mdigman
2 years ago
committed by
GitHub
5 changed files with 59 additions and 3 deletions
@ -0,0 +1,6 @@
|
||||
package org.jetbrains.compose.resources.vector.xmldom |
||||
|
||||
/** |
||||
* Error throw when parsed XML is malformed |
||||
*/ |
||||
class MalformedXMLException(message: String?) : Exception(message) |
@ -0,0 +1,17 @@
|
||||
package org.jetbrains.compose.resources.vector.xmldom |
||||
|
||||
import org.w3c.dom.Element as DomElement |
||||
|
||||
internal class ElementImpl(val element: DomElement): NodeImpl(element), Element { |
||||
|
||||
override val localName: String |
||||
get() = element.localName |
||||
|
||||
override val namespaceURI: String |
||||
get() = element.namespaceURI ?: "" |
||||
|
||||
override fun getAttributeNS(nameSpaceURI: String, localName: String): String = |
||||
element.getAttributeNS(nameSpaceURI, localName) ?: "" |
||||
|
||||
override fun getAttribute(name: String): String = element.getAttribute(name) ?: "" |
||||
} |
@ -0,0 +1,28 @@
|
||||
package org.jetbrains.compose.resources.vector.xmldom |
||||
|
||||
import org.w3c.dom.Node as DomNode |
||||
import org.w3c.dom.Element as DomElement |
||||
|
||||
internal open class NodeImpl(val n: DomNode): Node { |
||||
override val nodeName: String |
||||
get() = n.nodeName |
||||
|
||||
override val localName = "" /* localName is not a Node property, only applies to Elements and Attrs */ |
||||
|
||||
override val namespaceURI = "" /* namespaceURI is not a Node property, only applies to Elements and Attrs */ |
||||
|
||||
override val childNodes: NodeList by lazy { |
||||
object: NodeList { |
||||
override fun item(i: Int): Node { |
||||
val child = n.childNodes.item(i) |
||||
?: throw IndexOutOfBoundsException("no child node accessible at index=$i") |
||||
return if (child is DomElement) ElementImpl(child) else NodeImpl(child) |
||||
} |
||||
|
||||
override val length: Int = n.childNodes.length |
||||
} |
||||
} |
||||
|
||||
override fun lookupPrefix(namespaceURI: String): String = n.lookupPrefix(namespaceURI) ?: "" |
||||
|
||||
} |
Loading…
Reference in new issue