# Avoided if we are using Windows so that we can specify the directory to find the libxml DLL.
#  useDynLib(XML)

importFrom(utils, menu)
importFrom(grDevices, dev.off, jpeg, pdf, png)
import(methods)

export(
 append.xmlNode,
 append.XMLNode,
 Doctype,
 asXMLNode,
 comment.SAX,
 dtdElement,
 dtdElementValidEntry,
 dtdEntity,
 dtdIsAttribute,
 dtdValidElement,
 endElement.SAX,
 entityDeclaration.SAX,
 genericSAXHandlers,
 getNodeSet,
 xpathApply,
 htmlTreeParse,
 htmlParse,
 libxmlVersion,
 xmlDoc,
 newHTMLDoc,
 newXMLDoc,
 newXMLNode,
 newXMLNamespace,
 newXMLPINode,
 newXMLTextNode,
 newXMLCommentNode,
 newXMLCDataNode,
 newXMLDTDNode,
 parseDTD,
 processingInstruction.SAX,
 saveXML,
 startElement.SAX,
 supportsExpat,
 supportsLibxml,
 text.SAX,
 toString.XMLNode,
 xmlApply,
 xmlAttributeType,
 xmlAttrs,
 "xmlAttrs<-",
 xmlCDataNode,
 xmlChildren,
 xmlCommentNode,
 xmlContainsElement,
 xmlContainsEntity,
 xmlDOMApply,
 xmlElementsByTagName,
 xmlEventHandler,
 xmlEventParse,
# new.xmlEventParse,
# new.xmlTreeParse,
 xmlGetAttr,
 xmlHandler,
 xmlName,
 xmlNamespace,
 xmlNode,
 xmlOutputBuffer,
 xmlOutputDOM,
 xmlPINode,
 xmlParent,
 xmlAncestors,
 xmlRoot,
 xmlSApply,
 xmlSize,
 xmlSize.default,
 xmlTextNode,
 xmlTree,
 xmlTreeParse,
 xmlInternalTreeParse,
 xmlNativeTreeParse,
 xmlParse,
 xmlValue,
 names.XMLNode,
 parseURI,
 asXMLTreeNode,
 xmlHashTree,
 addNode,
 xmlNamespaceDefinitions,
 xmlNamespaces,
 matchNamespaces,
 getDefaultNamespace,
 catalogResolve,
 toHTML,
 addChildren,
 removeChildren,
 removeNodes,
 addAttributes,
 removeAttributes,
 "xmlName<-",
  addSibling
# xmlFlatListTree
)

S3method(removeNodes, "list")
S3method(removeNodes, "XMLNodeSet")
S3method(removeNodes, "XMLNodeList")
S3method(removeNodes, "XMLInternalNode")

exportMethods("addAttributes", "removeAttributes")

exportMethods("toHTML")

export("xmlChildren<-")
exportMethods("xmlChildren<-")

exportClasses("XMLInternalDocument", "XMLAbstractDocument")
exportClass("URI")
if(TRUE) {
exportClasses("XMLAbstractNode", "XMLNode")
exportClasses("HTMLInternalDocument")
exportClasses("XMLInternalNode", "XMLInternalElementNode",
              "XMLInternalTextNode", "XMLInternalPINode", "XMLInternalCDataNode",
              "XMLInternalCommentNode", "XMLDTDNode",
              "XMLXIncludeStartNode", "XMLXIncludeEndNode", "XMLEntityDeclNode",
              "XMLAttributeDeclNode", "XMLDocumentNode", "XMLDocumentTypeNode",
              "XMLDocumentFragNode", "XMLNamespaceDeclNode")
exportClass("XMLTreeNode")

exportClass(XMLNamespace)

exportClass(XMLNamespaceDefinitions)
}

exportMethods("coerce")

exportMethods("free")

S3method(removeChildren, XMLNode)
S3method(removeChildren, XMLInternalNode)

exportClasses(Percent, FormattedNumber, FormattedInteger)

S3method(xpathApply, XMLInternalNode)
S3method(xpathApply, XMLInternalDocument)
S3method(xpathApply, XMLNode)
export(xpathSApply)


S3method(xmlNamespaceDefinitions, XMLNode)
S3method(xmlNamespaceDefinitions, XMLInternalDocument)
S3method(xmlNamespaceDefinitions, XMLInternalNode)
S3method(xmlNamespaceDefinitions, XMLAbstractDocument)
#XXX S3method(xmlNamespaceDefinitions, XMLHashTreeNode)

#S3method(names, XMLFlatTree)
#S3method("$", XMLFlatListTree)

S3method(addNode, XMLHashTree)
S3method(xmlRoot, XMLHashTree)
S3method(print, XMLHashTree)

S3method(print, XMLInternalDocument)
S3method(print, XMLInternalNode)

S3method(print, XMLRDocument)
S3method(xmlRoot, XMLRDocument)
S3method(xmlRoot, HTMLDocument)


if(TRUE) {
S3method(xmlName, XMLComment)
S3method(xmlName, XMLNode)
S3method(xmlName, XMLInternalNode)
} else
  # S4 version
exportMethods(xmlName)

S3method("names<-", XMLNode)
S3method("xmlName<-", XMLNode)
S3method("xmlName<-", XMLInternalElementNode)





exportMethods("xmlAttrs<-")


if(TRUE) {
S3method(xmlChildren, XMLTreeNode)
S3method(xmlChildren, XMLInternalDocument)
S3method(xmlChildren, XMLHashTreeNode)
S3method(xmlChildren, XMLNode)
S3method(xmlChildren, XMLInternalNode)
} else
  exportMethods("xmlChildren")

if(FALSE)  {
S3method(xmlParent, XMLTreeNode)
S3method(xmlParent, XMLHashTreeNode)
S3method(xmlParent, XMLInternalNode)
} else
 exportMethods(xmlParent)


S3method(xmlSize, XMLHashTreeNode)


S3method(xmlSize, XMLHashTree)
S3method(xmlRoot, XMLHashTree)


S3method(xmlRoot, XMLInternalDOM)
S3method(xmlRoot, XMLInternalNode)


S3method(addChildren, XMLInternalNode)
S3method(addChildren, XMLInternalDocument)
S3method(addChildren, XMLNode)


export(replaceNodes)
S3method(replaceNodes, XMLInternalNode)



S3method(xmlSize, XMLInternalNode)


S3method(xmlValue, XMLInternalNode)

S3method(xmlValue, XMLNodeSet)
S3method(xmlValue, list)

#exportS3method("xmlValue", "NULL")
S3method("xmlValue", "NULL")

S3method("[", XMLNode)

if(TRUE) {
S3method("[[", XMLNode)
S3method("[[", XMLDocumentContent)

S3method("[[", XMLInternalNode)
S3method("[[", XMLInternalDocument)
S3method("[[", XMLHashTreeNode)
S3method("[[", XMLInternalElementNode)
}

S3method("[", XMLInternalNode)
S3method("[", XMLInternalDocument)
S3method("names", XMLInternalNode)
S3method("[<-", XMLNode)
S3method("[[<-", XMLNode)

S3method("[[<-", XMLInternalNode)

exportClass("XMLAttributes")
exportMethods("[")

export(xmlNamespaceDefinitions)


S3method(names, XMLNode)
S3method(length, XMLNode)

if(TRUE) {
 S3method(xmlAttrs, XMLNode)
 S3method(xmlAttrs, XMLInternalNode)
 S3method(xmlAttrs, XMLElementDef)
} else
  exportMethods("xmlAttrs")


S3method(xmlSize, XMLDocument)
S3method(xmlSize, default)
S3method(xmlSize, XMLNode)

S3method(print, XMLNode)
S3method(print, XMLTextNode)
S3method(print, XMLComment)
S3method(print, XMLCommentNode)
S3method(print, XMLEntityRef)
S3method(print, XMLCDataNode)
S3method(print, XMLProcessingInstruction)


S3method(xmlRoot, XMLDocument)
S3method(xmlRoot, XMLInternalDocument)
S3method(xmlRoot, XMLDocumentContent)

S3method(xmlApply, XMLNode)
S3method(xmlApply, XMLDocument)
S3method(xmlApply, XMLDocumentContent)
S3method(xmlApply, XMLInternalNode)

S3method(xmlSApply, XMLNode)
S3method(xmlSApply, XMLDocument)
S3method(xmlSApply, XMLDocumentContent)
S3method(xmlSApply, XMLInternalNode)

S3method(xmlSApply, XMLNodeSet)
S3method(xmlApply, XMLNodeSet)

if(TRUE) {
S3method(xmlValue, XMLNode)
S3method(xmlValue, XMLTextNode)
S3method(xmlValue, XMLComment)
S3method(xmlValue, XMLCDataNode)
S3method(xmlValue, XMLProcessingInstruction)
} else
 exportMethods("xmlValue")

S3method(addSibling, XMLInternalNode)

S3method(xmlNamespace, XMLNode)
S3method(xmlNamespace, XMLInternalNode)
S3method(xmlNamespace, character)

## formerly an unexported generic append() with uexported copy append.xmlNode()
S3method(append.xmlNode, XMLNode, append.XMLNode)
S3method(append.xmlNode, default)

exportMethods(saveXML)
# S3method(saveXML, XMLInternalDocument)
# S3method(saveXML, XMLInternalDOM)
# S3method(saveXML, XMLInternalNode)
# S3method(saveXML, XMLOutputStream)
# S3method(saveXML, XMLNode)
# S3method(saveXML, XMLFlatTree)

S3method(dtdElementValidEntry, XMLElementDef)
S3method(dtdElementValidEntry, XMLOrContent)
S3method(dtdElementValidEntry, XMLElementContent)
S3method(dtdElementValidEntry, character)
S3method(dtdElementValidEntry, XMLSequenceContent)

export(docName)
if(FALSE) {
S3method(docName, XMLDocument)
S3method(docName, XMLDocumentContent)
S3method(docName, XMLInternalDocument)
S3method(docName, XMLInternalNode)
S3method(docName, XMLHashTree)
} else
  exportMethods(docName)


export("xmlNamespaces<-")
exportMethods("xmlNamespaces<-")


export("docName<-")
exportMethods("docName<-")


exportClass("SAXState")

export(xmlSource)
exportMethods("xmlSource")
export(xmlSourceFunctions)
exportMethods("xmlSourceFunctions")
export(xmlSourceSection)
exportMethods("xmlSourceSection")


# Not yet exported....
#xmlValidity

if(TRUE) {
exportClasses("ExternalReference", "xmlSchemaRef", "libxmlTypeTable")
exportClasses("SchemaElementTable", "xmlSchemaElementRef",
              "SchemaTypeTable", "xmlSchemaTypeRef",
	      "SchemaAttributeTable", "xmlSchemaAttributeRef",
              "SchemaAttributeGroupTable", "xmlSchemaAttributeGroupRef",
              "SchemaNotationTable", "xmlSchemaNotationRef")

export(xmlSchemaValidate, schemaValidationErrorHandler, xmlSchemaParse)

exportMethods("names", "$", "$<-", "coerce")
}



#importFrom(utils, normalizePath)

export(getSibling)
S3method(getSibling, XMLInternalNode)
S3method(getSibling, XMLHashTreeNode)
export(catalogLoad, catalogClearTable, catalogAdd, catalogDump)


export(xmlStructuredStop, xmlErrorCumulator) # xmlStop
export(xmlStopParser)
export(getXMLErrors)

export(processXInclude)
S3method(processXInclude, list)
S3method(processXInclude, XMLInternalDocument)
S3method(processXInclude, XMLInternalElementNode)

exportMethods(show)

export(xmlElementSummary)
#, xmlElementSummaryHandlers)

#export(xmlNodeMatch)
#export(getRCode)


export(xmlParserContextFunction)

export(getRelativeURL)



export(xmlToList)

export('xmlValue<-')
exportMethods('xmlValue<-')


export(getEncoding)
exportMethods(getEncoding)

exportClass("XMLCodeFile")
exportClass("XMLCodeDoc")
exportMethods("[[")

export(xmlCodeFile)
exportMethods(source)


export(xmlClone)
export(findXInclude)

export(getLineNumber, getNodeLocation, getNodePosition)

export(ensureNamespace)

export(removeXMLNamespaces)
exportMethods(removeXMLNamespaces)


export(xmlParseDoc)

export(RECOVER,
      NOENT,
      DTDLOAD,
      DTDATTR,
      DTDVALID,
      NOERROR,
      NOWARNING,
      PEDANTIC,
      NOBLANKS,
      SAX1,
      XINCLUDE,
      NONET,
      NODICT,
      NSCLEAN,
      NOCDATA,
      NOXINCNODE,
      COMPACT,
      OLD10,
      NOBASEFIX,
      HUGE,
      OLDSAX)

export(libxmlFeatures)


exportClass("XMLString")
export(xml, xmlParseString, isXMLString)

export(readHTMLTable)




export(xmlToS4, makeClassTemplate) # xmlToS4List
exportMethods("xmlToS4")
export(xmlToDataFrame)
exportMethods(xmlToDataFrame)

export(compareXMLDocs)
S3method(summary, XMLInternalDocument)


export(parseXMLAndAdd)


#exportClass("XPathNodeSet")


export(xmlSerializeHook, xmlDeserializeHook)

if(FALSE) {
export(clearMemoryManagement)
exportMethods(clearMemoryManagement)
}

export("xmlParent<-")

export(xmlSearchNs)
export("xmlNamespace<-", setXMLNamespace)

export(readKeyValueDB, readSolrDoc)

export(getChildrenStrings)


export(getHTMLLinks)
export(readHTMLList)

export(getXIncludes, xmlXIncludes)
export(getHTMLExternalFiles)

export(xmlCleanNamespaces)

export(replaceNodeWithChildren)

S3method(toString, XMLNode)

S3method(addNode, XMLFlatListTree)
S3method(removeNodes, default)
S3method(replaceNodes, list)
S3method(xmlRoot, XMLFlatTree)
S3method(xmlRoot, XMLInternalElement)
S3method(xmlValue, XMLCommentNode)
S3method(xpathApply, XMLDocument)
