SAX parse XML text.
        @param file: Parse a python I{file-like} object.
        @type file: I{file-like} object.
        @param string: Parse string XML.
        @type string: str
502847
def parse(self, file=None, string=None):
        
        timer = metrics.Timer()
        timer.start()
        sax, handler = self.saxparser()
        if file is not None:
            sax.parse(file)
            timer.stop()
            metrics.log.debug('sax (%s) duration: %s', file, timer)
            return handler.nodes[0]
        if string is not None:
            source = InputSource(None)
            source.setByteStream(StringIO(string))
            sax.parse(source)
            timer.stop()
            metrics.log.debug('%s\nsax duration: %s', string, timer)
            return handler.nodes[0]
1319562
private static Document parseXmlToDocument(final File xmlFile) {
        Document result = null;
        Reader reader = null;
        try {
            reader = new FileReader(xmlFile);
            result = parseXmlStream(reader);
        } catch (FileNotFoundException e) {
            // This should never happen...
        } finally {
            IOUtil.close(reader);
        }

        return result;
    }
564494
public void load(String file) throws Exception {

		try {
			InputStreamReader  read = new InputStreamReader (new FileInputStream(file),"utf-8");
			BufferedReader lbin = new BufferedReader(read);
			String str;
			while((str=lbin.readLine())!=null){
				if(str.length()==0)
					continue;
				if(str.charAt(0)=='#')
					continue;
				add(new BaseTemplet(gid++, str));
			}
			lbin.close();
		} catch (IOException e1) {
			e1.printStackTrace();
			throw new Exception("读入模板错误");
		}catch (Exception e) {
			e.printStackTrace();
			throw new Exception("读入模板错误");
		}
	}
1141644
public static void load(File file)
    {
        try(FileInputStream inputStream = new FileInputStream(file))
        {
            LineIterator it = IOUtils.lineIterator(inputStream, "UTF-8");
            while (it.hasNext())
            {
                String line = it.next();
                if (!line.startsWith("#") && !line.trim().isEmpty())
                {
                    add(line);
                }
            }
        }
        catch (Exception e)
        {
            throw new WindupException("Failed loading archive ignore patterns from [" + file.toString() + "]", e);
        }
    }
495161
public Collection<XLog> parse(File file) throws Exception {
		Collection<XLog> result = null;
		for(XParser parser : XParserRegistry.instance().getAvailable()) {
			if(parser.canParse(file)) {
				try {
					result = parser.parse(file);
					return result;
				} catch(Exception e) {
					// ignore and move on
				}
			}
		}
		throw new Exception("No suitable parser could be found!");
	}
1248420
def parse( file )
      pattern = PATTERNS[ File.extname( file ) ]

      IO.readlines( file ).take_while do |line|
        line =~ pattern
      end.map { |line| line[ pattern, 1 ] }
    end
516090
def read_xml(filename):
    
    parser = et.XMLParser(remove_blank_text=True)
    isfile=False
    try:
        isfile = os.path.exists(filename)
    except ValueError as e:
        if 'path too long for Windows' in str(e):
            pass
        else:
            raise
    try:
        if isfile:
            return et.parse(filename, parser)
        else:
            r = et.fromstring(filename, parser)
            return r.getroottree()
    except IOError:
        log.exception('unable to open file [[}]'.format(filename))
    except et.XMLSyntaxError:
        log.exception('unable to parse XML [{}]'.format(filename))
        return None
    return None
344718
public void parse(File f, DefaultHandler dh) throws SAXException, IOException
    {
        XMLReader reader = getXMLReader();
        InputSource source = new InputSource(new FileInputStream(f));
        reader.setContentHandler(dh);
        reader.parse(source);
    }
843264
function parse(context, file) {
  var message

  if (stats(file).fatal) {
    return
  }

  if (context.treeIn) {
    debug('Not parsing already parsed document')

    try {
      context.tree = json(file.toString())
    } catch (error) {
      message = file.message(
        new Error('Cannot read file as JSON\n' + error.message)
      )
      message.fatal = true
    }

    /* Add the preferred extension to ensure the file, when compiled, is
     * correctly recognized. Only add it if there’s a path — not if the
     * file is for example stdin. */
    if (file.path) {
      file.extname = context.extensions[0]
    }

    file.contents = ''

    return
  }

  debug('Parsing `%s`', file.path)

  context.tree = context.processor.parse(file)

  debug('Parsed document')
}
61821
public static XNElement parseXML(String fileName) throws IOException, XMLStreamException {
        try (InputStream in = new FileInputStream(fileName)) {
            return parseXML(in);
        }
    }
212327
public static Configuration load(String file)
    throws IOException, SAXException {
    ConfigurationImpl cfg = new ConfigurationImpl();

    XMLReader parser = XMLReaderFactory.createXMLReader();
    parser.setContentHandler(new ConfigHandler(cfg, file));
    if (file.startsWith("classpath:")) {
      String resource = file.substring("classpath:".length());
      ClassLoader cloader = Thread.currentThread().getContextClassLoader();
      InputStream istream = cloader.getResourceAsStream(resource);
      parser.parse(new InputSource(istream));
    } else
      parser.parse(file);

    return cfg;
  }
648078
public static String readTextFile(File file) {
        try {
            return readTextFile(new FileReader(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
1054463
public static synchronized ConfigParser setConfigFile(String file) {
        LOGGER.entering(file);
        if (configuration == null) {
            configFile = file;
        }
        LOGGER.exiting(parser.toString());
        return parser;
    }
944623
def main_from_xml(file)
      xml_data = File.read(file)
      xml_data.force_encoding('utf-8')

      doc = Nokogiri::XML(xml_data)
      doc.elements.first.elements.first
    end
722676
def _parse_file(self, file):
        
        case = Case()
        file.seek(0)
        case.base_mva = float(file.next().split(",")[1].split("/")[0])
        case.name = "%s %s" % (file.next().strip(), file.next().strip())

        bustype_map = {1: "PQ", 2: "PV", 3: "ref", 4: "isolated"}

        # I, 'NAME', BASKV, IDE, GL, BL, AREA, ZONE, VM, VA, OWNER
        bus_data = file.next().split(",")
        while bus_data[0].strip()[0] != "0":
            bus = Bus()
            i = int(bus_data[0].strip())
            self.bus_map[i] = bus
            bus._i = i
            bus.name =  bus_data[1].strip("'").strip()
            bus.v_base = float(bus_data[2])
            bus.type = bustype_map[int(bus_data[3])]
            bus.g_shunt = float(bus_data[4])
            bus.b_shunt = float(bus_data[5])
            bus.v_magnitude = float(bus_data[8])
            bus.v_angle = float(bus_data[9])
            # bus.area = 1;  # hcui7 added
            case.buses.append(bus)
            bus_data = file.next().split(",")

        # I, ID, STATUS, AREA, ZONE, PL, QL, IP, IQ, YP, YQ, OWNER
        load_data = file.next().split(",")
        while load_data[0].strip()[0] != "0":
            bus = self.bus_map[int(load_data[0].strip())]
            bus.p_demand += float(load_data[5])
            bus.q_demand += float(load_data[6])
            load_data = file.next().split(",")

        #I,ID,PG,QG,QT,QB,VS,IREG,MBASE,ZR,ZX,RT,XT,GTAP,STAT,RMPCT,PT,PB,O1,F1
        gen_data = file.next().split(",")
        while gen_data[0].strip()[0] != "0":
            bus = self.bus_map[int(gen_data[0].strip())]
            g = Generator(bus)
            g.p = float(gen_data[2])
            g.q = float(gen_data[3])
            g.q_max = float(gen_data[4])
            g.q_min = float(gen_data[5])
            g.v_magnitude = float(gen_data[6])
            g.base_mva = float(gen_data[8])
            g.online = bool(int(gen_data[14]))
            g.p_max = float(gen_data[16])
            g.p_min = float(gen_data[17])
            case.generators.append(g)
            gen_data = file.next().split(",")

        # I,J,CKT,R,X,B,RATEA,RATEB,RATEC,GI,BI,GJ,BJ,ST,LEN,O1,F1,...,O4,F4
        branch_data = file.next().split(",")
        while branch_data[0].strip()[0] != "0":
            from_bus = self.bus_map[abs(int(branch_data[0]))]
            to_bus = self.bus_map[abs(int(branch_data[1]))]
            l = Branch(from_bus, to_bus)
            l.r = float(branch_data[3])
            l.x = float(branch_data[4])
            l.b = float(branch_data[5])
            l.rate_a = float(branch_data[6])
            l.rate_b = float(branch_data[7])
            l.rate_c = float(branch_data[8])
#            l.online = bool(int(branch_data[13]))
            case.branches.append(l)
            branch_data = file.next().split(",")

        # I,J,K,CKT,CW,CZ,CM,MAG1,MAG2,NMETR,'NAME',STAT,O1,F1,...,O4,F4
        # R1-2,X1-2,SBASE1-2
        # WINDV1,NOMV1,ANG1,RATA1,RATB1,RATC1,COD1,CONT1,RMA1,RMI1,VMA1,VMI1,NTP1,TAB1,CR1,CX1
        # WINDV2,NOMV2
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            trx_data2 = file.next().split(",")
            trx_data3 = file.next().split(",")
            trx_data4 = file.next().split(",") # second winding
            if len(trx_data2) < 5:
                from_bus = self.bus_map[abs(int(trx_data[0]))]
                to_bus = self.bus_map[abs(int(trx_data[1]))]
                l = Branch(from_bus, to_bus)
                l.name = trx_data[10].strip("'").strip()
                l.online = bool(int(trx_data[11]))
                l.b = float(trx_data[8])
                l.r = float(trx_data2[0])
                l.x = float(trx_data2[1])
                l.ratio = float(trx_data3[0])
                l.phase_shift = float(trx_data3[2])
                rate_a = float(trx_data3[3])
                if rate_a != 0.0:
                    l.rate_a = rate_a
                rate_b = float(trx_data3[4])
                if rate_b != 0.0:
                    l.rate_b = rate_b
                rate_c = float(trx_data3[5])
                if rate_c != 0.0:
                    l.rate_c = rate_c
                case.branches.append(l)
                trx_data = file.next().split(",")
            else:
                # I,J,K,CKT,CW,CZ,CM,MAG1,MAG2,NMETR,'NAME',STAT,O1,F1,...,O4,F4
                # R1-2,X1-2,SBASE1-2,R2-3,X2-3,SBASE2-3,R3-1,X3-1,SBASE3-1,VMSTAR,ANSTAR
                # WINDV1,NOMV1,ANG1,RATA1,RATB1,RATC1,COD1,CONT1,RMA1,RMI1,VMA1,VMI1,NTP1,TAB1,CR1,CX1
                # WINDV2,NOMV2,ANG2,RATA2,RATB2,RATC2,COD2,CONT2,RMA2,RMI2,VMA2,VMI2,NTP2,TAB2,CR2,CX2
                # WINDV3,NOMV3,ANG3,RATA3,RATB3,RATC3,COD3,CONT3,RMA3,RMI3,VMA3,VMI3,NTP3,TAB3,CR3,CX3

                trx_data5 = file.next().split(",") # third winding
                # Three-winding transformers are modelled as a group of three
                # two-winding transformers with a fictitious neutral bus.
                tmp_bus = Bus()
                tmp_bus.name = "n" + tmp_bus.name
                tmp_bus._i = len(case.buses) + 1

                bus1 = self.bus_map[abs(int(trx_data[0]))]
                bus2 = self.bus_map[abs(int(trx_data[1]))]
                bus3 = self.bus_map[abs(int(trx_data[2]))]
                l1 = Branch(tmp_bus, bus1)
                l2 = Branch(tmp_bus, bus2)
                l3 = Branch(tmp_bus, bus3)

                b = float(trx_data[8]) # MAG2
                l1.b = b# / 3.0
#                l2.b = b / 3.0
#                l3.b = b / 3.0

                on = bool(int(trx_data[11]))
                l1.online = on
                l2.online = on
                l3.online = on

                r12 = float(trx_data2[0])
                x12 = float(trx_data2[1])
                r23 = float(trx_data2[3])
                x23 = float(trx_data2[4])
                r31 = float(trx_data2[6])
                x31 = float(trx_data2[7])

                l1.r = 0.5 * (r12 + r31 - r23)
                l1.x = 0.5 * (x12 + x31 - x23)
                l2.r = 0.5 * (r12 + r23 - r31)
                l2.x = 0.5 * (x12 + x23 - x31)
                l3.r = 0.5 * (r23 + r31 - r12)
                l3.x = 0.5 * (x23 + x31 - x12)

                for l in [l1, l2, l3]:
                    if abs(l.x) < 1e-5:
                        logger.warning("Zero branch reactance [%s]." % l.name)
                        l.x = self.xtol
                    if abs(complex(l.r, l.x)) < 0.00001:
                        logger.warning("Zero branch impedance [%s]." % l.name)

                l1.ratio = float(trx_data3[0])
                l1.phase_shift = float(trx_data3[2])
                l2.ratio = float(trx_data4[0])
                l2.phase_shift = float(trx_data4[2])
                l3.ratio = float(trx_data5[0])
                l3.phase_shift = float(trx_data5[2])

                rate_a1 = float(trx_data3[3])
                rate_b1 = float(trx_data3[4])
                rate_c1 = float(trx_data3[5])
                if rate_a1 > 0.0:
                    l1.rate_a = rate_a1
                if rate_b1 > 0.0:
                    l1.rate_b = rate_b1
                if rate_c1 > 0.0:
                    l1.rate_c = rate_c1

                rate_a2 = float(trx_data4[3])
                rate_b2 = float(trx_data4[4])
                rate_c2 = float(trx_data4[5])
                if rate_a2 > 0.0:
                    l2.rate_a = rate_a2
                if rate_b2 > 0.0:
                    l2.rate_b = rate_b2
                if rate_c2 > 0.0:
                    l2.rate_c = rate_c2

                rate_a3 = float(trx_data5[3])
                rate_b3 = float(trx_data5[4])
                rate_c3 = float(trx_data5[5])
                if rate_a3 > 0.0:
                    l3.rate_a = rate_a3
                if rate_b2 > 0.0:
                    l3.rate_b = rate_b3
                if rate_c2 > 0.0:
                    l3.rate_c = rate_c3

                case.buses.append(tmp_bus)
                case.branches.append(l1)
                case.branches.append(l2)
                case.branches.append(l3)

                trx_data = file.next().split(",")

        # Area interchange data.
        # I, ISW, PDES, PTOL, 'ARNAME'
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring area interchange data.")
            trx_data = file.next().split(",")

        # Two-terminal DC line data.
        # I,MDC,RDC,SETVL,VSCHD,VCMOD,RCOMP,DELTI,METER,DCVMIN,CCCITMX,CCCACC
        # IPR,NBR,ALFMX,ALFMN,RCR,XCR,EBASR,TRR,TAPR,TMXR,TMNR,STPR,ICR,IFR,ITR,IDR,XCAPR
        # IPI,NBI,GAMMX,GAMMN,RCI,XCI,EBASI,TRI,TAPI,TMXI,TMNI,STPI,ICI,IFI,ITI,IDI,XCAPI
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring two-terminal DC line data.")
            trx_data = file.next().split(",")

        # VSC DC line data.
        # 'NAME', MDC, RDC, O1, F1, ... O4, F4
        # IBUS,TYPE,MODE,DOCET,ACSET,ALOSS,BLOSS,MINOSS,SMAX,IMAX,PWF,MAXQ,MINQ,
        # REMOT,RMPCT
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring VSC DC line data.")
            trx_data = file.next().split(",")

        # Switched shunt data.
        # I,MODSW,VSWHI,VSWLO,SWREM,RMPCT,'RMIDNT',BINIT,N1,B1,N2,B2,...N8,B8
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            bus = self.bus_map[abs(int(trx_data[0]))]
            bus.b_shunt += float(trx_data[7])
            trx_data = file.next().split(",")

        # Transformer impedance correction table.
        # I, T1, F1, T2, F2, T3, F3, ... T11, F11
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring transformer X correction table data.")
            trx_data = file.next().split(",")

        # Multi-terminal dc line data.
        # I, NCONV, NDCBS, NDCLN, MDC, VCONV, VCMOD, VCONVN
        # IB,N,ANGMX,ANGMN,RC,XC,EBAS,TR,TAP,TPMX,TPMN,TSTP,SETVL,DCPF,MARG,CNVCOD
        # IDC, IB, IA, ZONE, 'NAME', IDC2, RGRND, OWNER
        # IDC, JDC, DCCKT, RDC, LDC
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring multi-terminal dc line data.")
            trx_data = file.next().split(",")

        # Multisection line data.
        # I,J,ID,DUM1,DUM2,...DUM9
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring multisection line data.")
            trx_data = file.next().split(",")

        # Zone data.
        # I,'ZONAME'
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring zone data.")
            trx_data = file.next().split(",")

        # Interarea transfer data.
        # ARFROM, ARTO, TRID, PTRAN
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring interarea transfer data.")
            trx_data = file.next().split(",")

        # Owner data.
        # I,'OWNAME'
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring owner data.")
            trx_data = file.next().split(",")

        # FACTS device data.
        # N,I,J,MODE,PDES,QDES,VSET,SHMX,TRMX,VTMN,VTMX,VSMX,IMX,LINX,RMPCT,OWNER,SET1,SET2,VSREF
        trx_data = file.next().split(",")
        while trx_data[0].strip()[0] != "0":
            logger.warning("Ignoring FACTS device data.")
            trx_data = file.next().split(",")

        return case
565894
public Map<String, Object> processFile(File file) {
        ParserEngine engine = Engines.get(FileUtil.fileExt(file));
        if (engine==null) {
            LOGGER.error("Unable to find suitable markup engine for {}",file);
            return null;
        }

        return engine.parse(config, file);
    }
399171
public void parse(File xmlFile) throws XMLStreamException {
    try (InputStream input = java.nio.file.Files.newInputStream(xmlFile.toPath())) {
      parse(input);
    } catch (IOException e) {
      LOG.debug("Cannot access file", e);
    }
  }