XML manipulation.
Parses a string representation of XML into a structured form that Orc can manipulate.
site XMLElement(String, {. .}, List[XML]) :: XML
Creates an XML element node with the given tag, attributes, and children. This site may also be used for matching.
Creates an XML text node with the given contents. Encoding may occur. This site may also be used for matching.
Creates an XML text node with the given contents. Contents will not be encoded. This site may also be used for matching.
def xml(String, List[XML]) :: XML
Creates an XML element with the given tag and children, and no attributes. May also be used for matching. When matching, the second argument is a multimatch on each child, rather than a match on the list of children.
Implementation.
val xml = def toxml(String, List[Top]) :: XML def toxml(tag, children) = def liftChild(Top) :: XML def liftChild(x) = IsXML(x) ; XMLText("" + x) XMLElement(tag, {. .}, map(liftChild, children)) def fromxml(XML) :: Top def fromxml(XMLElement(tag,attr,children)) = each(children) >c> ( c >XMLElement(_,_,_)> (tag,c) | c >XMLText(s)> (tag,s) | c >XMLCData(s)> (tag,s) ) def fromxml(XMLText(s)) = s def fromxml(XMLCData(s)) = s {. apply = toxml, unapply = fromxml .}
Creates a copy of the XML element, adding new attributes as given by the record argument. If there is a conflict, the new attributes override the old ones. May also be used for matching.
Implementation.
val xattr = def toattr(XML, {. .}) :: XML def toattr(XMLElement(tag, attr, children), moreattr) = XMLElement(tag, attr + moreattr, children) def fromattr(XML) :: (XML, {. .}) def fromattr(XMLElement(tag, attr, children)) = (XMLElement(tag, {. .}, children), attr) {. apply = toattr, unapply = fromattr .}