/* *
Parses a document with the text/html parser and validates it.
489259
private void checkAsHTML(InputSource is) throws IOException, SAXException {
        sourceCode.initialize(is);
        try {
            htmlReader.parse(is);
        } catch (SAXParseException e) {
        }
    }
452803
public static Document parse(String html, String baseUri) {
        TreeBuilder treeBuilder = new HtmlTreeBuilder();
        return treeBuilder.parse(new StringReader(html), baseUri, new Parser(treeBuilder));
    }
1201035
function HTMLReactParser(html, options) {
  if (typeof html !== 'string') {
    throw new TypeError('First argument must be a string');
  }
  return domToReact(htmlToDOM(html, domParserOptions), options);
}
475125
def parse_and_validate_response(body, options = {})
        dom = REXML::Document.new(body)

        if (value = options[:root_name]) && dom.root.name != value
          raise ResponseError, "Invalid response, root node is not `#{value}`"
        end
        if (value = options[:root_text]) && dom.root.text != value
          raise ResponseError, value
        end

        dom
      end
198851
public void parse(Document document) {
        responsePayLoad = document.getDocumentElement();
        status = responsePayLoad.getAttribute("stat");
        if ("ok".equals(status)) {
            Element photoIdElement = (Element) responsePayLoad.getElementsByTagName("photoid").item(0);
            if (photoIdElement != null) {
                photoId = ((Text) photoIdElement.getFirstChild()).getData();
            } else {
                photoId = null;
            }
            Element ticketIdElement = (Element) responsePayLoad.getElementsByTagName("ticketid").item(0);
            if (ticketIdElement != null) {
                ticketId = ((Text) ticketIdElement.getFirstChild()).getData();
            } else {
                ticketId = null;
            }
        } else {
            Element errElement = (Element) responsePayLoad.getElementsByTagName("err").item(0);
            errorCode = errElement.getAttribute("code");
            errorMessage = errElement.getAttribute("msg");
        }
    }
1222365
function DocCommentParser(text) {
  this.lines = text.split(END_OF_LINE);
  this.lineNumber = 0;
  this.length = this.lines.length;
  this.line = '';

  this.match = [];
  this.tagDef = {};

  this.mode = this._extractLine;

  this.data = {};
}
251975
function parse(doc,context){
	var vs;
	var cmds=[];
	var pats;
	var exprs;
	var subpats;
	var mode=context.mode;

	var vs=splitLine_(doc);
	for(var i=0;i<vs.length;i++){
		if(pats=vs[i].match(macroRegex)){
			if(mode=='tcmd'){
				console.log(pats[1]+','+pats[2]);
			}
			exprs=null;
			switch(pats[1]){
			case 'define':
				if(subpats=pats[2].match(defineRegex)){
					exprs=[subpats[1],subpats[2]];
				}else{
					console.log("error: invalid format in define statement "+pats[1]+" in line "+(i+1));
				}
				break;
			case 'include':
			case 'include_once':
			case 'include_code':
			case 'include_code_once':
				exprs=toExpr(pats[2],i+1);
				break;
			case 'if':
			case 'elseif':
			case 'elif':
				exprs=toExpr(pats[2],i+1);
				break;
			case 'else':
			case 'endif':
				break;
			case 'namespace':
				if(subpats=pats[2].match(nsRegex)){
					setNamespace_(subpats[1]);
				}else{
					console.log("error: invalid format in namespace statement "+pats[1]+" in line "+(i+1));
				}
				break;
			default:
				if(pats[1].charAt(0)!='@'){
					console.log("error: unknown statement "+pats[1]+" in line "+(i+1));
				}
				break;
			}
			cmds.push({type:pats[1], exprs:exprs});
		}else{
			cmds.push({type:'text', value:vs[i]});
		}
	}
	if(mode=='cmd'){
		for(var i=0;i<cmds.length;i++){
			console.log(JSON.stringify(cmds[i]));
		}
	}
	return cmds;
}
1214205
function DocParser(){
  return {
    doc: makeBlock('Document', 1, 1),
    tip: this.doc,
    refmap: {},
    inlineParser: new InlineParser(),
    breakOutOfLists: breakOutOfLists,
    addLine: addLine,
    addChild: addChild,
    incorporateLine: incorporateLine,
    finalize: finalize,
    processInlines: processInlines,
    parse: parse
  };
}
1022983
function parseText(parts, tag, h, param, continuationMarker, state) {
    var end = parts.length;
    if (!endTagRe.hasOwnProperty(tag.name)) {
      endTagRe[tag.name] = new RegExp('^' + tag.name + '(?:[\\s\\/]|$)', 'i');
    }
    var re = endTagRe[tag.name];
    var first = tag.next;
    var p = tag.next + 1;
    for (; p < end; p++) {
      if (parts[p - 1] === '<\/' && re.test(parts[p])) { break; }
    }
    if (p < end) { p -= 1; }
    var buf = parts.slice(first, p).join('');
    if (tag.eflags & html4.eflags.CDATA) {
      if (h.cdata) {
        h.cdata(buf, param, continuationMarker,
          continuationMaker(h, parts, p, state, param));
      }
    } else if (tag.eflags & html4.eflags.RCDATA) {
      if (h.rcdata) {
        h.rcdata(normalizeRCData(buf), param, continuationMarker,
          continuationMaker(h, parts, p, state, param));
      }
    } else {
      throw new Error('bug');
    }
    return p;
  }
368189
function isValidSelector(value) {
    "use strict";
    if (isString(value)) {
        try {
            // phantomjs env has a working document object, let's use it
            document.querySelector(value);
        } catch(e) {
            if ('name' in e && (e.name === 'SYNTAX_ERR' || e.name === 'SyntaxError')) {
                return false;
            }
        }
        return true;
    } else if (isObject(value)) {
        if (!value.hasOwnProperty('type')) {
            return false;
        }
        if (!value.hasOwnProperty('path')) {
            return false;
        }
        if (['css', 'xpath'].indexOf(value.type) === -1) {
            return false;
        }
        return true;
    }
    return false;
}
434095
function parse(contents, retained, parser) {
    var errors = [], data = [], lines = 0;

    // optional parser
    if (!parser) parser = JSON;

    // process each line of the file
    contents.toString().split('\n').forEach(function(line) {
        if (!line) return;
        lines++;
        try {
            data.push(parser.parse(line));
        } catch (e) {
            e.line = line;
            errors.push(e);
        }
    });

    // if no errors/data, don't return an empty array
    var ret = {};
    if (errors.length) ret.errors = errors;
    if (data.length) ret.data = data;

    // if every line failed, probably not line-delimited
    if (errors.length == lines) ret.errors = retained;

    return ret;
}
814919
function documentParser(content) {
  var safeContent = safeEndingTags(content);

  var body = void 0;
  var head = void 0;

  try {
    var $ = _dom2.default.parseXML(safeContent);

    body = $('mjml > mj-body');
    head = $('mjml > mj-head');

    if (body.length > 0) {
      body = body.children().get(0);
    }
  } catch (e) {
    throw new _Error.ParseError('Error while parsing the file');
  }

  if (!body || body.length < 1) {
    throw new _Error.EmptyMJMLError('No root "<mjml>" or "<mj-body>" found in the file, or "<mj-body>" doesn\'t contain a child element.');
  }

  return {
    tagName: 'mjml',
    children: [{
      tagName: 'mj-head',
      children: head && head.length > 0 ? parseHead(head.get(0)) : []
    }, {
      tagName: 'mj-body',
      children: [mjmlElementParser(body, safeContent)]
    }]
  };
}
623889
private Document parseBytesToDocument(String pid, byte[] bytes)
            throws InvalidContentModelException {
        try {
            DocumentBuilderFactory factory =
                    DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(new ByteArrayInputStream(bytes));
        } catch (ParserConfigurationException e) {
            throw new InvalidContentModelException(pid, "Failed to parse "
                    + DS_COMPOSITE_MODEL, e);
        } catch (SAXException e) {
            throw new InvalidContentModelException(pid, "Failed to parse "
                    + DS_COMPOSITE_MODEL, e);
        } catch (IOException e) {
            throw new InvalidContentModelException(pid, "Failed to parse "
                    + DS_COMPOSITE_MODEL, e);
        }
    }
1353122
function parseHtml(html, sourceCodeStore) {
    const isFragment = !/^\s*<(!doctype|html|head|body|!--)/iu.test(html)
    const document = (isFragment ? parse5.parseFragment : parse5.parse)(html, {
        sourceCodeLocationInfo: true,
    })

    return parse5NodeToToken(document, null, html, sourceCodeStore, html.length)
}
301254
function Parser(html, opts) {
        // fake root node
        html = util.trim(html);
        this.originalHTML = html;    // only allow condition
                                     // 1. start with <!doctype
                                     // 2. start with <!html
                                     // 3. start with <!body
                                     // 4. not start with <head
                                     // 5. not start with <meta
        // only allow condition
        // 1. start with <!doctype
        // 2. start with <!html
        // 3. start with <!body
        // 4. not start with <head
        // 5. not start with <meta
        if (/^(<!doctype|<html|<body)/i.test(html)) {
            html = '<document>' + html + '</document>';
        } else {
            html = '<body>' + html + '</body>';
        }
        this.lexer = new Lexer(html);
        this.opts = opts || {};
    }
640150
function parseText(text) {
  text = text.replace(/\n/g, '')
  /* istanbul ignore if */
  if (!tagRE.test(text)) {
    return null
  }
  var tokens = []
  var lastIndex = tagRE.lastIndex = 0
  var match, index, html, value, first, oneTime
  /* eslint-disable no-cond-assign */
  while (match = tagRE.exec(text)) {
  /* eslint-enable no-cond-assign */
    index = match.index
    // push text token
    if (index > lastIndex) {
      tokens.push({
        value: text.slice(lastIndex, index)
      })
    }
    // tag token
    html = htmlRE.test(match[0])
    value = html ? match[1] : match[2]
    first = value.charCodeAt(0)
    oneTime = first === 42 // *
    value = oneTime
      ? value.slice(1)
      : value
    tokens.push({
      tag: true,
      value: value.trim(),
      html: html,
      oneTime: oneTime
    })
    lastIndex = index + match[0].length
  }
  if (lastIndex < text.length) {
    tokens.push({
      value: text.slice(lastIndex)
    })
  }
  return tokens
}
924639
function parseCustomHtmlToReact(html, context) {
  if (!defined(html) || html.length === 0) {
    return html;
  }
  return htmlToReactParser.parseWithInstructions(
    html,
    isValidNode,
    getProcessingInstructions(context || {})
  );
}