static int import_oftree( char *filename ) { oftree.allnext = NULL; oftree.root = import_node( filename, NULL ); return oftree.root ? 0:1; }
mol_device_node_t * prom_import_node( mol_device_node_t *par, const char *filename ) { mol_device_node_t *dn; if( !par ) { printm("import_node: NULL parent\n"); return NULL; } dn = import_node( filename, par); return dn; }
static void* import_binary (int argc, char **argv, void *data) { Node *node = (Node *) data; char *filename = argc==2?argv[1]:""; import_state_t ist; int moredata=1; FILE *file; file = fopen (filename, "r"); if (!file) { cli_outfunf ("binary import, unable to open \"%s\"", filename); return node; } {int header,version; fread(&header, sizeof(int), 1, file); fread(&version, sizeof(int), 1, file); if(header!=hnb_binary_header || version!=hnb_binary_version){ cli_outfunf("binary import, header mismatch"); } } init_import(&ist, node); while(moredata){ int attributes; int level; moredata=fread(&level, sizeof(int), 1, file); if(!moredata) break; fread(&attributes, sizeof(int),1,file); if(!moredata) break; if(level || attributes){ Node *temp_node=node_new(); while(attributes){ int len; char *att_name; char *att_data; fread(&len, sizeof(int),1,file); att_name=malloc(len+1); fread(att_name,1,len,file); att_name[len]='\0'; fread(&len, sizeof(int),1,file); att_data=malloc(len+1); fread(att_data,1,len,file); att_data[len]='\0'; node_set(temp_node, att_name, att_data); free(att_name); free(att_data); attributes--; } import_node(&ist,level,temp_node); temp_node=NULL; } } if(node_getflag(node,F_temp)) node=node_remove(node); cli_outfunf("binary import - imported \"%s\"",filename); return node; }
DomNode DomDocument::import_node(const DomNode &node, bool deep) { DomNode imported_node; switch (node.get_node_type()) { case NULL_NODE: return imported_node; case ELEMENT_NODE: imported_node = create_element_ns(node.get_namespace_uri(), node.get_node_name()); break; case ATTRIBUTE_NODE: imported_node = create_attribute_ns(node.get_namespace_uri(), node.get_node_name()); imported_node.set_node_value(node.get_node_value()); break; case TEXT_NODE: imported_node = create_text_node(node.get_node_value()); break; case CDATA_SECTION_NODE: imported_node = create_cdata_section(node.get_node_value()); break; case ENTITY_REFERENCE_NODE: imported_node = create_entity_reference(node.get_node_name()); break; case ENTITY_NODE: return imported_node; case PROCESSING_INSTRUCTION_NODE: imported_node = create_processing_instruction(node.to_processing_instruction().get_target(), node.to_processing_instruction().get_data()); break; case COMMENT_NODE: imported_node = create_comment(node.get_node_value()); break; case DOCUMENT_NODE: imported_node = create_document_fragment(); break; case DOCUMENT_TYPE_NODE: return imported_node; case DOCUMENT_FRAGMENT_NODE: imported_node = create_document_fragment(); break; case NOTATION_NODE: return imported_node; } if (node.is_element()) { DomElement import_element = imported_node.to_element(); DomNamedNodeMap node_attributes = node.get_attributes(); int size = node_attributes.get_length(); for (int index = 0; index < size; index++) { DomNode attr = node_attributes.item(index); import_element.set_attribute_node_ns(import_node(attr, deep).to_attr()); } } if (deep) { DomNode cur = node.get_first_child(); while (!cur.is_null()) { imported_node.append_child(import_node(cur, true)); cur = cur.get_next_sibling(); } } return imported_node; }