void StyledHRDMapper::loadRegionMappings(InputSource *is) { DocumentBuilder docbuilder; Document *hrdbase = docbuilder.parse(is); Element *hbase = hrdbase->getDocumentElement(); if (*hbase->getNodeName() != "hrd"){ docbuilder.free(hrdbase); throw Exception(DString("Error loading HRD file")); }; for(Node *curel = hbase->getFirstChild(); curel; curel = curel->getNextSibling()){ if (curel->getNodeType() == Node::ELEMENT_NODE && *curel->getNodeName() == "assign"){ const String *name = ((Element*)curel)->getAttribute(DString("name")); if (name == null) continue; if (regionDefines.get(name) != null){ delete regionDefines.get(name); } int val = 0; bool bfore = UnicodeTools::getNumber(((Element*)curel)->getAttribute(DString("fore")), &val); int fore = val; bool bback = UnicodeTools::getNumber(((Element*)curel)->getAttribute(DString("back")), &val); int back = val; int style = 0; if (UnicodeTools::getNumber(((Element*)curel)->getAttribute(DString("style")), &val)){ style = val; } RegionDefine *rdef = new StyledRegion(bfore, bback, fore, back, style); regionDefines.put(name, rdef); }; }; docbuilder.free(hrdbase); };
void ConsoleTools::setLinkSource(const String &str){ InputSource *linkSource = null; DocumentBuilder docbuilder; Document *linkSourceTree = null; try{ linkSource = InputSource::newInstance(&str); linkSourceTree = docbuilder.parse(linkSource); }catch(Exception &e){ docbuilder.free(linkSourceTree); throw e; } Node *elem = linkSourceTree->getDocumentElement(); if (*elem->getNodeName() != "doclinks"){ throw Exception(DString("Bad doclinks data file structure")); } elem = elem->getFirstChild(); while(elem != null){ if (elem->getNodeType() == Node::ELEMENT_NODE && *elem->getNodeName() == "links"){ const String *url = ((Element*)elem)->getAttribute(DString("url")); const String *scheme = ((Element*)elem)->getAttribute(DString("scheme")); Node *eachLink = elem->getFirstChild(); while(eachLink != null){ if (*eachLink->getNodeName() == "link"){ const String *l_url = ((Element*)eachLink)->getAttribute(DString("url")); const String *l_scheme = ((Element*)eachLink)->getAttribute(DString("scheme")); const String *token = ((Element*)eachLink)->getAttribute(DString("token")); StringBuffer fullURL; if (url != null) fullURL.append(url); if (l_url != null) fullURL.append(l_url); if (l_scheme == null) l_scheme = scheme; if (token == null) continue; StringBuffer hkey(token); if (l_scheme != null && l_scheme->length() > 0){ hkey.append(DString("--")).append(l_scheme); } docLinkHash->put(&hkey, new SString(&fullURL)); } eachLink = eachLink->getNextSibling(); } } elem = elem->getNextSibling(); } delete linkSource; docbuilder.free(linkSourceTree); }
void ReadAppXml::read(std::string filePathName) throw(Exception) { Document *doc = 0; //建立一个解析器工厂 DocumentBuilderFactory *factory = DocumentBuilderFactory::newInstance(); //获得一个DocumentBuilder对象,这个对象代表了具体的DOM解析器 DocumentBuilder *builder = factory->newDocumentBuilder(); //得到一个表示XML文档的Document对象 doc = builder->parse(filePathName); //去掉XML文档中作为格式化内容的空白而映射在DOM树中的不必要的Text Node对象 doc->normalize(); // //获取jdbc // NodeList jdbc = doc.getElementsByTagName("jdbc"); // //只有一个jdbc,获取jdbc中的驱动类的名称 // NodeList driverClassNode = ((Element)jdbc.item(0)).getElementsByTagName("driver-class"); // String driverClass = driverClassNode.item(0).getFirstChild().getNodeValue(); // System.out.println("driverClass=="+driverClass); // //同理获取url、user、password等值 // NodeList urlNode = ((Element)jdbc.item(0)).getElementsByTagName("url"); // String url = urlNode.item(0).getFirstChild().getNodeValue(); // System.out.println("url=="+url); // // NodeList userNode = ((Element)jdbc.item(0)).getElementsByTagName("user"); // String user = userNode.item(0).getFirstChild().getNodeValue(); // System.out.println("user=="+user); // // NodeList passwordNode = ((Element)jdbc.item(0)).getElementsByTagName("password"); // String password = passwordNode.item(0).getFirstChild().getNodeValue(); // System.out.println("password=="+password); // //获取application-xml // NodeList applicationXmlNode = doc.getElementsByTagName("application-xml"); // String applicationXml = applicationXmlNode.item(0).getFirstChild().getNodeValue(); // System.out.println("applicationXml=="+applicationXml); //先要获取spring-default,然后获取application-xmls //然后才能获取application-xml NodeList *springDefaultNode = doc->getElementsByTagName("spring-default"); NodeList *appXmlsNode = (static_cast<Element *>(springDefaultNode->item(0)))->getElementsByTagName("application-xmls"); NodeList *appXmlNode = (static_cast<Element *>(appXmlsNode->item(0)))->getElementsByTagName("application-xml"); //循环获取每个application-xml元素的值 for (int i = 0; i < appXmlNode->getLength(); i++) { std::string applicationXml = appXmlNode->item(i)->getFirstChild()->getNodeValue(); puts("applicationXml==" + applicationXml); } }
/** Loads region definitions from HRD file. Multiple files could be loaded. */ void TextHRDMapper::loadRegionMappings(InputSource *is) { DocumentBuilder docbuilder; Document *hrdbase = docbuilder.parse(is); Element *hbase = hrdbase->getDocumentElement(); if (*hbase->getNodeName() != "hrd"){ docbuilder.free(hrdbase); throw Exception(DString("Error loading HRD file")); }; for(Node *curel = hbase->getFirstChild(); curel; curel = curel->getNextSibling()){ if (curel->getNodeType() == Node::ELEMENT_NODE && *curel->getNodeName() == "assign"){ const String *name = ((Element*)curel)->getAttribute(DString("name")); if (name == null) continue; if (regionDefines.get(name) != null){ const TextRegion *rd = TextRegion::cast(regionDefines.get(name)); delete rd->stext; delete rd->etext; delete rd->sback; delete rd->eback; delete rd; }; const String *stext = null; const String *etext = null; const String *sback = null; const String *eback = null; const String *sval; sval = ((Element*)curel)->getAttribute(DString("stext")); if (sval != null) stext = new SString(sval); sval = ((Element*)curel)->getAttribute(DString("etext")); if (sval != null) etext = new SString(sval); sval = ((Element*)curel)->getAttribute(DString("sback")); if (sval != null) sback = new SString(sval); sval = ((Element*)curel)->getAttribute(DString("eback")); if (sval != null) eback = new SString(sval); RegionDefine *rdef = new TextRegion(stext, etext, sback, eback); regionDefines.put(name, rdef); }; }; docbuilder.free(hrdbase); };
void FarHrcSettings::readXML(String *file, bool userValue) { DocumentBuilder docbuilder; InputSource *dfis = InputSource::newInstance(file); Document *xmlDocument = docbuilder.parse(dfis); Element *types = xmlDocument->getDocumentElement(); if (*types->getNodeName() != "hrc-settings"){ docbuilder.free(xmlDocument); throw FarHrcSettingsException(DString("main '<hrc-settings>' block not found")); } for (Node *elem = types->getFirstChild(); elem; elem = elem->getNextSibling()){ if (*elem->getNodeName() == "prototype"){ UpdatePrototype((Element*)elem, userValue); continue; } }; docbuilder.free(xmlDocument); delete dfis; }