Java Code Examples for org.xmlpull.v1.XmlPullParserFactory#setNamespaceAware()

The following examples show how to use org.xmlpull.v1.XmlPullParserFactory#setNamespaceAware() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLTVParser.java    From ChannelSurfer with MIT License 6 votes vote down vote up
public static List<Program> parse(String in) throws XmlPullParserException, IOException {
        try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(true);
            XmlPullParser xpp = factory.newPullParser();
            Log.d(TAG, "Start parsing");
            Log.d(TAG, in.substring(0, 36));
            xpp.setInput(new StringReader(in));
            int eventType = xpp.getEventType();
            Log.d(TAG, eventType+"");
//            if(eventType == XmlPullParser.START_DOCUMENT)
//                xpp.next();
            /*
            xpp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
            xpp.setInput(new InputStreamReader(in));*/
            /*xpp.nextTag();
            xpp.nextTag();
            */return readFeed(xpp);
        } finally {
//            in.close();
        }
    }
 
Example 2
Source File: Main.java    From WeChatLuckyMoney with Apache License 2.0 6 votes vote down vote up
private String getFromXml(String xmlmsg, String node) throws XmlPullParserException, IOException {
    String xl = xmlmsg.substring(xmlmsg.indexOf("<msg>"));
    //nativeurl
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser pz = factory.newPullParser();
    pz.setInput(new StringReader(xl));
    int v = pz.getEventType();
    String result = "";
    while (v != XmlPullParser.END_DOCUMENT) {
        if (v == XmlPullParser.START_TAG) {
            if (pz.getName().equals(node)) {
                pz.nextToken();
                result = pz.getText();
                break;
            }
        }
        v = pz.next();
    }
    return result;
}
 
Example 3
Source File: Rss2Parser.java    From PkRSS with Apache License 2.0 6 votes vote down vote up
public Rss2Parser() {
	// Initialize DateFormat object with the default date formatting
	dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
	dateFormat.setTimeZone(Calendar.getInstance().getTimeZone());
	pattern = Pattern.compile("-\\d{1,4}x\\d{1,4}");

	// Initialize XmlPullParser object with a common configuration
	XmlPullParser parser = null;
	try {
		XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
		factory.setNamespaceAware(false);
		parser = factory.newPullParser();
	}
	catch (XmlPullParserException e) {
		e.printStackTrace();
	}
	xmlParser = parser;
}
 
Example 4
Source File: XmlToJson.java    From alipay-master with GNU General Public License v3.0 6 votes vote down vote up
private
@Nullable
JSONObject convertToJSONObject() {
    try {
        Tag parentTag = new Tag("", "xml");

        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(false);   // tags with namespace are taken as-is ("namespace:tagname")
        XmlPullParser xpp = factory.newPullParser();

        setInput(xpp);

        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.START_DOCUMENT) {
            eventType = xpp.next();
        }
        readTags(parentTag, xpp);

        unsetInput();

        return convertTagToJson(parentTag, false);
    } catch (XmlPullParserException | IOException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 5
Source File: XmlToJson.java    From WechatEnhancement with GNU General Public License v3.0 6 votes vote down vote up
private
@Nullable
JSONObject convertToJSONObject() {
    try {
        Tag parentTag = new Tag("", "xml");

        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(false);   // tags with namespace are taken as-is ("namespace:tagname")
        XmlPullParser xpp = factory.newPullParser();

        setInput(xpp);

        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.START_DOCUMENT) {
            eventType = xpp.next();
        }
        readTags(parentTag, xpp);

        unsetInput();

        return convertTagToJson(parentTag, false);
    } catch (XmlPullParserException | IOException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 6
Source File: WeChatHelper.java    From WechatHook-Dusan with Apache License 2.0 6 votes vote down vote up
public static String getFromXml(String xmlmsg, String node) throws XmlPullParserException, IOException {
    String xl = xmlmsg.substring(xmlmsg.indexOf("<msg>"));
    //nativeurl
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser pz = factory.newPullParser();
    pz.setInput(new StringReader(xl));
    int eventType = pz.getEventType();
    String result = "";
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
            if (pz.getName().equals(node)) {
                pz.nextToken();
                result = pz.getText();
                break;
            }
        }
        eventType = pz.next();
    }
    return result;
}
 
Example 7
Source File: XmlParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected XmlPullParser loadXml(InputStream stream) throws XmlPullParserException, IOException {
	BufferedInputStream input = new BufferedInputStream(stream);
	XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
	factory.setNamespaceAware(true);
	factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, false);
	XmlPullParser xpp = factory.newPullParser();
	xpp.setInput(input, "UTF-8");
	next(xpp);
	nextNoWhitespace(xpp);

	return xpp;
}
 
Example 8
Source File: Utilities.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
static
XmlPullParser createXmlParser(CharSequence urlString) throws IOException, XmlPullParserException
{
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser parser = factory.newPullParser();

    URL url = new URL(urlString.toString());
    InputStream inputStream = url.openStream();
    parser.setInput(inputStream, null);
    return parser;
}
 
Example 9
Source File: ToolsHelper.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected XmlPullParser loadXml(InputStream stream) throws XmlPullParserException, IOException {
	BufferedInputStream input = new BufferedInputStream(stream);
	XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
	factory.setNamespaceAware(true);
	XmlPullParser xpp = factory.newPullParser();
	xpp.setInput(input, "UTF-8");
	xpp.next();
	return xpp;
}
 
Example 10
Source File: GoogleSuggestionsModel.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
private static synchronized XmlPullParser getParser() throws XmlPullParserException {
    if (sXpp == null) {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        sXpp = factory.newPullParser();
    }
    return sXpp;
}
 
Example 11
Source File: XmlParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected XmlPullParser loadXml(InputStream stream) throws XmlPullParserException, IOException {
	BufferedInputStream input = new BufferedInputStream(stream);
	XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
	factory.setNamespaceAware(true);
	XmlPullParser xpp = factory.newPullParser();
	xpp.setInput(input, "UTF-8");
	next(xpp);
	nextNoWhitespace(xpp);

	return xpp;
}
 
Example 12
Source File: XmlParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected XmlPullParser loadXml(InputStream stream) throws XmlPullParserException, IOException {
	BufferedInputStream input = new BufferedInputStream(stream);
	XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
	factory.setNamespaceAware(true);
	factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, false);
	XmlPullParser xpp = factory.newPullParser();
	xpp.setInput(input, "UTF-8");
	next(xpp);
	nextNoWhitespace(xpp);

	return xpp;
}
 
Example 13
Source File: Dsmlv2ResponseParser.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of Dsmlv2ResponseParser.
 *
 * @param codec The Ldap Service to use
 * @throws XmlPullParserException if an error occurs while the initialization of the parser
 */
public Dsmlv2ResponseParser( LdapApiService codec ) throws XmlPullParserException
{
    this.container = new Dsmlv2Container( codec );

    this.container.setGrammar( Dsmlv2ResponseGrammar.getInstance() );

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware( true );
    XmlPullParser xpp = factory.newPullParser();

    container.setParser( xpp );
}
 
Example 14
Source File: AmazonInfoRetriever.java    From BarcodeEye with Apache License 2.0 5 votes vote down vote up
private static XmlPullParser buildParser(CharSequence contents) throws XmlPullParserException {
  XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  factory.setNamespaceAware(true);
  XmlPullParser xpp = factory.newPullParser();
  xpp.setInput(new StringReader(contents.toString()));
  return xpp;
}
 
Example 15
Source File: Dsmlv2Parser.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of Dsmlv2Parser.
 *
 * @param grammar The grammar in use
 * @throws XmlPullParserException if an error occurs during the initialization of the parser
 */
public Dsmlv2Parser( Dsmlv2Grammar grammar ) throws XmlPullParserException
{
    this.container = new Dsmlv2Container( grammar.getLdapCodecService() );
    this.container.setGrammar( grammar );
    this.grammar = grammar;

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware( true );
    XmlPullParser xpp = factory.newPullParser();

    container.setParser( xpp );
}
 
Example 16
Source File: XmlParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected XmlPullParser loadXml(InputStream stream) throws XmlPullParserException, IOException {
	BufferedInputStream input = new BufferedInputStream(stream);
	XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
	factory.setNamespaceAware(true);
	factory.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, false);
	XmlPullParser xpp = factory.newPullParser();
	xpp.setInput(input, "UTF-8");
	next(xpp);
	nextNoWhitespace(xpp);

	return xpp;
}
 
Example 17
Source File: TrustKitConfigurationTest.java    From TrustKit-Android with MIT License 5 votes vote down vote up
private XmlPullParser parseXmlString(String xmlString) throws XmlPullParserException {
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);

    XmlPullParser xpp = factory.newPullParser();
    String test = xmlString.replace("\n","").replace("  ","");
    xpp.setInput(new StringReader(test));
    return xpp;
}
 
Example 18
Source File: Driver.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 */
public Driver() throws XmlPullParserException {
    final XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    pp = factory.newPullParser();
}
 
Example 19
Source File: SLDHandler.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/** Helper method for finding which style handler/version to use from the actual content. */
Object[] getVersionAndReader(Object input) throws IOException {
    // need to determine version of sld from actual content
    BufferedReader reader = null;

    if (input instanceof InputStream) {
        reader = RequestUtils.getBufferedXMLReader((InputStream) input, XML_LOOKAHEAD);
    } else {
        reader = RequestUtils.getBufferedXMLReader(toReader(input), XML_LOOKAHEAD);
    }

    String version;
    try {
        // create stream parser
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(false);

        // parse root element
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(reader);
        parser.nextTag();

        version = null;
        for (int i = 0; i < parser.getAttributeCount(); i++) {
            if ("version".equals(parser.getAttributeName(i))) {
                version = parser.getAttributeValue(i);
            }
        }

        parser.setInput(null);
    } catch (XmlPullParserException e) {
        throw (IOException) new IOException("Error parsing content").initCause(e);
    }

    // reset input stream
    reader.reset();

    if (version == null) {
        LOGGER.warning("Could not determine SLD version from content. Assuming 1.0.0");
        version = "1.0.0";
    }

    return new Object[] {new Version(version), reader};
}
 
Example 20
Source File: PepXMLFileImport.java    From PDV with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Return additional parameters
 * @throws IOException
 * @throws XmlPullParserException
 */
private void getScoreName() throws IOException, XmlPullParserException {

    BufferedReader bufferedReader = new BufferedReader(new FileReader(pepXMLFile));

    checkPeptideProphet(new BufferedReader(new FileReader(pepXMLFile)));

    XmlPullParserFactory xmlPullParserFactory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
    xmlPullParserFactory.setNamespaceAware(true);
    XmlPullParser xmlPullParser = xmlPullParserFactory.newPullParser();

    xmlPullParser.setInput(bufferedReader);

    String tagName;
    int tagNum;
    while ((tagNum = xmlPullParser.next()) != XmlPullParser.START_TAG) {
    }

    while (tagNum != XmlPullParser.END_DOCUMENT) {
        tagName = xmlPullParser.getName();

        if (tagName != null) {
            if (tagNum == XmlPullParser.START_TAG && xmlPullParser.getName().equals("search_score")) {
                String name = null;
                String value = null;
                for (int i = 0; i < xmlPullParser.getAttributeCount(); i++) {
                    String attributeName = xmlPullParser.getAttributeName(i);
                    if (attributeName.equals("name")) {
                        name = xmlPullParser.getAttributeValue(i).replaceAll("[^a-zA-Z]", "");
                        if(name.length() >= 30){
                            name = name.substring(0, 29);
                        }
                    } else if (attributeName.equals("value")) {
                        value = xmlPullParser.getAttributeValue(i);
                    }
                    if(!scoreName.contains(name)){
                        scoreName.add(name);
                    }
                }
            } else if (tagNum == XmlPullParser.END_TAG && tagName.equals("search_hit")) {
                break;
            }
        }
        tagNum = xmlPullParser.next();
    }
}