public static IRubyObject constructNode(Ruby runtime, Node node) {
if (node == null) return runtime.getNil();
// this is slow; need a way to cache nokogiri classes/modules somewhere
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
XmlElement xmlElement = (XmlElement) NokogiriService.XML_ELEMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Element"));
xmlElement.setNode(runtime.getCurrentContext(), node);
return xmlElement;
case Node.ATTRIBUTE_NODE:
XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Attr"));
xmlAttr.setNode(runtime.getCurrentContext(), node);
return xmlAttr;