當前位置: 首頁>>代碼示例>>Java>>正文


Java XmlPullParser.getPrefix方法代碼示例

本文整理匯總了Java中org.xmlpull.v1.XmlPullParser.getPrefix方法的典型用法代碼示例。如果您正苦於以下問題:Java XmlPullParser.getPrefix方法的具體用法?Java XmlPullParser.getPrefix怎麽用?Java XmlPullParser.getPrefix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.xmlpull.v1.XmlPullParser的用法示例。


在下文中一共展示了XmlPullParser.getPrefix方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: captureElement

import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
/**
 * Serializes the current element and all child nodes as a String.
 * @param parser The parser to pull from.
 * @return The composed element string.
 * @throws XmlPullParserException
 * @throws IOException
 */
public static String captureElement(XmlPullParser parser)
        throws XmlPullParserException, IOException
{
    int event = parser.getEventType();
    if (event != XmlPullParser.START_TAG) {
        throw new XmlPullParserException("Expected call to begin at START_TAG");
    }
    int depth = 0;

    StringWriter sw = new StringWriter();
    XmlSerializer serializer = PARSER_FACTORY.newSerializer();
    serializer.setOutput(sw);

    String namespace, prefix;
    while (event != XmlPullParser.END_DOCUMENT) {
        switch (event) {
            case XmlPullParser.START_TAG:
                ++depth;
                namespace = parser.getNamespace();
                prefix = parser.getPrefix();
                if (namespace != null && prefix != null) {
                    serializer.setPrefix(prefix, namespace);
                }
                serializer.startTag(namespace, parser.getName());
                int attrCount = parser.getAttributeCount();
                for (int i = 0; i < attrCount; ++i) {
                    namespace = parser.getAttributeNamespace(i);
                    prefix = parser.getAttributePrefix(i);
                    if (namespace != null && prefix != null) {
                        serializer.setPrefix(prefix, namespace);
                    }
                    serializer.attribute(namespace, parser.getAttributeName(i),
                            parser.getAttributeValue(i));
                }
                break;

            case XmlPullParser.TEXT:
            case XmlPullParser.IGNORABLE_WHITESPACE:
                serializer.text(parser.getText());
                break;

            case XmlPullParser.CDSECT:
                serializer.cdsect(parser.getText());
                break;

            case XmlPullParser.END_TAG:
                namespace = parser.getNamespace();
                if (namespace != null) {
                    serializer.setPrefix(parser.getPrefix(), namespace);
                }
                serializer.endTag(namespace, parser.getName());
                --depth;
                break;
        }
        if (depth <= 0) {
            serializer.flush();
            return sw.toString();
        }

        event = parser.next();
    }
    throw new IOException("Unexpected end of document.");
}
 
開發者ID:Axe-Ishmael,項目名稱:Blockly,代碼行數:71,代碼來源:BlocklyXmlHelper.java

示例2: parsiElsendojnDeRssVinilkosmo

import org.xmlpull.v1.XmlPullParser; //導入方法依賴的package包/類
/** Parser et youtube RSS feed og returnerer det som en liste at Elsendo-objekter */
private static ArrayList<Udsendelse> parsiElsendojnDeRssVinilkosmo(Reader is) throws Exception {
  XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  XmlPullParser p = factory.newPullParser();
  p.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
  p.setInput(is);
  ArrayList<Udsendelse> liste = new ArrayList<Udsendelse>();
  Udsendelse e = null;
  while (true) {
    int eventType = p.next();
    if (eventType == XmlPullParser.END_DOCUMENT) {
      break;
    }
    if (eventType != XmlPullParser.START_TAG) {
      continue;
    }
    String ns = p.getPrefix(); // namespace
    String tag = p.getName();
    //System.out.println("<" + ns + ":" + tag + ">");

    if ("entry".equals(tag)) {
      if (e != null && e.sonoUrl.size()>0) liste.add(e);
      e = new Udsendelse();
    } else if (e == null) {
      continue;
    } else if ("title".equals(tag)) {
      e.titel = EoDiverse.unescapeHtml3(p.nextText());
    } else if ("published".equals(tag)) {
      String txt = p.nextText();
      e.startTidKl = txt.split("T")[0];
      //Log.d("e.datoStr="+e.datoStr);
      e.startTid = EsperantoRadioBackend.datoformato.parse(e.startTidKl);
      e.startTidKl = EsperantoRadioBackend.datoformato.format(e.startTid);
      e.slug = "vk:"+txt.split("\\+")[0];
    } else if ("link".equals(tag)) {
      String type = p.getAttributeValue(null, "type");
      String href = p.getAttributeValue(null, "href");
      if ("audio/mpeg".equals(type)) {
        e.sonoUrl.add(href);
      } else if ("image/jpeg".equals(type) && e.billedeUrl ==null) {
        e.billedeUrl =href;
      } else if ("text/html".equals(type)) {
        e.shareLink =href;
      }
    } else if ("content".equals(tag)) {
      e.beskrivelse = p.nextText().trim();
      e.beskrivelse = puriguVinilkosmo.matcher(e.beskrivelse).replaceAll("");
      while (e.beskrivelse.startsWith("<p>")) e.beskrivelse = e.beskrivelse.substring(3).trim();
      while (e.beskrivelse.startsWith("</div>")) e.beskrivelse = e.beskrivelse.substring(6).trim();
    }
  }
  if (e != null && e.sonoUrl.size()>0) liste.add(e);
  is.close();
  return liste;
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:56,代碼來源:EoRssParsado.java


注:本文中的org.xmlpull.v1.XmlPullParser.getPrefix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。