当前位置: 首页>>代码示例>>Java>>正文


Java XMLStreamConstants.PROCESSING_INSTRUCTION属性代码示例

本文整理汇总了Java中javax.xml.stream.XMLStreamConstants.PROCESSING_INSTRUCTION属性的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamConstants.PROCESSING_INSTRUCTION属性的具体用法?Java XMLStreamConstants.PROCESSING_INSTRUCTION怎么用?Java XMLStreamConstants.PROCESSING_INSTRUCTION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.xml.stream.XMLStreamConstants的用法示例。


在下文中一共展示了XMLStreamConstants.PROCESSING_INSTRUCTION属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: nextTagSkipDTD

/**
 * A copy of the nextTag algorithm from the XMLStreamReader javadocs,
 * but which also skips over DTD events as well as whitespace,
 * comments and PIs.
 * 
 * @param xsr the reader to advance
 * @return {@link XMLStreamConstants#START_ELEMENT} or
 *         {@link XMLStreamConstants#END_ELEMENT} for the next tag.
 * @throws XMLStreamException
 */
private static int nextTagSkipDTD(XMLStreamReader xsr)
        throws XMLStreamException {
  int eventType = xsr.next();
  while((eventType == XMLStreamConstants.CHARACTERS && xsr.isWhiteSpace())
          || (eventType == XMLStreamConstants.CDATA && xsr.isWhiteSpace())
          || eventType == XMLStreamConstants.SPACE
          || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
          || eventType == XMLStreamConstants.COMMENT
          || eventType == XMLStreamConstants.DTD) {
    eventType = xsr.next();
  }
  if(eventType != XMLStreamConstants.START_ELEMENT
          && eventType != XMLStreamConstants.END_ELEMENT) {
    throw new XMLStreamException("expected start or end tag", xsr
            .getLocation());
  }
  return eventType;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:28,代码来源:DocumentStaxUtils.java

示例2: nextTag

/** Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION)
 * until a START_ELEMENT or
 * END_ELEMENT is reached. If other than space characters are
 * encountered, an exception is thrown. This method should
 * be used when processing element-only content because
 * the parser is not able to recognize ignorable whitespace if
 * then DTD is missing or not interpreted.
 * @return the event type of the element read
 * @throws XMLStreamException if the current event is not white space
 */
public int nextTag() throws XMLStreamException {

    int eventType = next();
    while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
    || (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
    // skip whitespace
    || eventType == XMLStreamConstants.SPACE
    || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
    || eventType == XMLStreamConstants.COMMENT
    ) {
        eventType = next();
    }

    if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
        throw new XMLStreamException(
                "found: " + getEventTypeString(eventType)
                + ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT)
                + " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT),
                getLocation());
    }

    return eventType;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:XMLStreamReaderImpl.java

示例3: getEventTypeName

private static String getEventTypeName(int eventType) {
  switch (eventType) {
    case XMLStreamConstants.START_ELEMENT:
      return "START_ELEMENT";
    case XMLStreamConstants.END_ELEMENT:
      return "END_ELEMENT";
    case XMLStreamConstants.SPACE:
      return "SPACE";
    case XMLStreamConstants.CHARACTERS:
      return "CHARACTERS";
    case XMLStreamConstants.PROCESSING_INSTRUCTION:
      return "PROCESSING_INSTRUCTION";
    case XMLStreamConstants.CDATA:
      return "CDATA";
    case XMLStreamConstants.COMMENT:
      return "COMMENT";
    case XMLStreamConstants.ENTITY_REFERENCE:
      return "ENTITY_REFERENCE";
    case XMLStreamConstants.START_DOCUMENT:
      return "START_DOCUMENT";
    case XMLStreamConstants.END_DOCUMENT:
      return "END_DOCUMENT";
  }
  return null;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:25,代码来源:XMLStreamHelper.java

示例4: nextTag

/**
 * Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION) until
 * a START_ELEMENT or END_ELEMENT is reached. If other than space characters
 * are encountered, an exception is thrown. This method should be used when
 * processing element-only content because the parser is not able to
 * recognize ignorable whitespace if then DTD is missing or not interpreted.
 *
 * @return the event type of the element read
 * @throws XMLStreamException if the current event is not white space
 */
public int nextTag() throws XMLStreamException {

    int eventType = next();
    while ((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
            || (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
            // skip whitespace
            || eventType == XMLStreamConstants.SPACE
            || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
            || eventType == XMLStreamConstants.COMMENT) {
        eventType = next();
    }

    if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
        throw new XMLStreamException(
                "found: " + getEventTypeString(eventType)
                + ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT)
                + " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT),
                getLocation());
    }

    return eventType;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:XMLStreamReaderImpl.java

示例5: getXMLs

@DataProvider(name = "xmls")
public Object[][] getXMLs() {

    return new Object[][]{
        {"<?xml version='1.0'?><foo/>",
            XMLStreamConstants.START_DOCUMENT, XMLStreamConstants.START_ELEMENT},
        {"<foo/>",
            XMLStreamConstants.START_DOCUMENT, XMLStreamConstants.START_ELEMENT},
        {"<?xml version='1.0'?>"
            + "<?xml-stylesheet href=\"bar.xsl\" type=\"text/xsl\"?>" +
                "<foo/>",
            XMLStreamConstants.START_DOCUMENT, XMLStreamConstants.PROCESSING_INSTRUCTION},
        {"<?xml-stylesheet href=\"bar.xsl\" type=\"text/xsl\"?>" +
                "<foo/>",
            XMLStreamConstants.START_DOCUMENT, XMLStreamConstants.PROCESSING_INSTRUCTION},
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:BugTest.java

示例6: testPITargetAndData

@Test
public void testPITargetAndData() {
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        String PITarget = "soffice";
        String PIData = "WebservicesArchitecture";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<?" + PITarget + " " + PIData + "?>" + "<foo></foo>";
        // System.out.println("XML = " + xml) ;
        InputStream is = new java.io.ByteArrayInputStream(xml.getBytes());
        XMLStreamReader sr = xif.createXMLStreamReader(is);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION) {
                String target = sr.getPITarget();
                String data = sr.getPIData();
                Assert.assertTrue(target.equals(PITarget) && data.equals(PIData));
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ProcessingInstructionTest.java

示例7: getEventName

/**
 * Get the human readable event name for the numeric event id
 */
public static String getEventName(int eventId) {
	switch (eventId) {
		case XMLStreamConstants.START_ELEMENT:
			return "StartElementEvent";
		case XMLStreamConstants.END_ELEMENT:
			return "EndElementEvent";
		case XMLStreamConstants.PROCESSING_INSTRUCTION:
			return "ProcessingInstructionEvent";
		case XMLStreamConstants.CHARACTERS:
			return "CharacterEvent";
		case XMLStreamConstants.COMMENT:
			return "CommentEvent";
		case XMLStreamConstants.START_DOCUMENT:
			return "StartDocumentEvent";
		case XMLStreamConstants.END_DOCUMENT:
			return "EndDocumentEvent";
		case XMLStreamConstants.ENTITY_REFERENCE:
			return "EntityReferenceEvent";
		case XMLStreamConstants.ATTRIBUTE:
			return "AttributeBase";
		case XMLStreamConstants.DTD:
			return "DTDEvent";
		case XMLStreamConstants.CDATA:
			return "CDATA";
	}
	return "UNKNOWN_EVENT_TYPE";
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:XMLStreamConstantsUtils.java

示例8: getEventTypeString

public final static String getEventTypeString(int eventType) {
    switch (eventType){
        case XMLStreamConstants.START_ELEMENT:
            return "START_ELEMENT";
        case XMLStreamConstants.END_ELEMENT:
            return "END_ELEMENT";
        case XMLStreamConstants.PROCESSING_INSTRUCTION:
            return "PROCESSING_INSTRUCTION";
        case XMLStreamConstants.CHARACTERS:
            return "CHARACTERS";
        case XMLStreamConstants.COMMENT:
            return "COMMENT";
        case XMLStreamConstants.START_DOCUMENT:
            return "START_DOCUMENT";
        case XMLStreamConstants.END_DOCUMENT:
            return "END_DOCUMENT";
        case XMLStreamConstants.ENTITY_REFERENCE:
            return "ENTITY_REFERENCE";
        case XMLStreamConstants.ATTRIBUTE:
            return "ATTRIBUTE";
        case XMLStreamConstants.DTD:
            return "DTD";
        case XMLStreamConstants.CDATA:
            return "CDATA";
    }
    return "UNKNOWN_EVENT_TYPE";
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:Util.java

示例9: getElementText

/** Reads the content of a text-only element. Precondition:
 * the current event is START_ELEMENT. Postcondition:
 * The current event is the corresponding END_ELEMENT.
 * @throws XMLStreamException if the current event is not a START_ELEMENT or if
 * a non text element is encountered
 */
public String getElementText() throws XMLStreamException {

    if(getEventType() != XMLStreamConstants.START_ELEMENT) {
        throw new XMLStreamException(
        "parser must be on START_ELEMENT to read next text", getLocation());
    }
    int eventType = next();
    StringBuffer content = new StringBuffer();
    while(eventType != XMLStreamConstants.END_ELEMENT ) {
        if(eventType == XMLStreamConstants.CHARACTERS
        || eventType == XMLStreamConstants.CDATA
        || eventType == XMLStreamConstants.SPACE
        || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
            content.append(getText());
        } else if(eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
        || eventType == XMLStreamConstants.COMMENT) {
            // skipping
        } else if(eventType == XMLStreamConstants.END_DOCUMENT) {
            throw new XMLStreamException("unexpected end of document when reading element text content");
        } else if(eventType == XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException(
            "elementGetText() function expects text only elment but START_ELEMENT was encountered.", getLocation());
        } else {
            throw new XMLStreamException(
            "Unexpected event type "+ eventType, getLocation());
        }
        eventType = next();
    }
    return content.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:XMLStreamReaderImpl.java

示例10: nextTag

/** Skips any insignificant space events until a START_ELEMENT or
 * END_ELEMENT is reached. If anything other than space characters are
 * encountered, an exception is thrown. This method should
 * be used when processing element-only content because
 * the parser is not able to recognize ignorable whitespace if
 * the DTD is missing or not interpreted.
 * @throws XMLStreamException if anything other than space characters are encountered
 */
public XMLEvent nextTag() throws XMLStreamException {
    //its really a pain if there is peeked event before calling nextTag()
    if(fPeekedEvent != null){
        //check the peeked event first.
        XMLEvent event = fPeekedEvent;
        fPeekedEvent = null ;
        int eventType = event.getEventType();
        //if peeked event is whitespace move to the next event
        //if peeked event is PI or COMMENT move to the next event
        if( (event.isCharacters() && event.asCharacters().isWhiteSpace())
        || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
        || eventType == XMLStreamConstants.COMMENT
        || eventType == XMLStreamConstants.START_DOCUMENT){
            event = nextEvent();
            eventType = event.getEventType();
        }

        //we have to have the while loop because there can be many PI or comment event in sucession
        while((event.isCharacters() && event.asCharacters().isWhiteSpace())
        || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
        || eventType == XMLStreamConstants.COMMENT){

            event = nextEvent();
            eventType = event.getEventType();
        }

        if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
            throw new XMLStreamException("expected start or end tag", event.getLocation());
        }
        return event;
    }

    //if there is no peeked event -- delegate the work of getting next event to fXMLReader
    fXMLReader.nextTag();
    return (fLastEvent = fXMLEventAllocator.allocate(fXMLReader));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:XMLEventReaderImpl.java

示例11: getElementText

/**
 * Reads the content of a text-only element. Precondition: the current event
 * is START_ELEMENT. Postcondition: The current event is the corresponding
 * END_ELEMENT.
 *
 * @throws XMLStreamException if the current event is not a START_ELEMENT or
 * if a non text element is encountered
 */
public String getElementText() throws XMLStreamException {

    if (getEventType() != XMLStreamConstants.START_ELEMENT) {
        throw new XMLStreamException(
                "parser must be on START_ELEMENT to read next text", getLocation());
    }
    int eventType = next();
    StringBuilder content = new StringBuilder();
    while (eventType != XMLStreamConstants.END_ELEMENT) {
        if (eventType == XMLStreamConstants.CHARACTERS
                || eventType == XMLStreamConstants.CDATA
                || eventType == XMLStreamConstants.SPACE
                || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
            content.append(getText());
        } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
                || eventType == XMLStreamConstants.COMMENT) {
            // skipping
        } else if (eventType == XMLStreamConstants.END_DOCUMENT) {
            throw new XMLStreamException(
                    "unexpected end of document when reading element text content");
        } else if (eventType == XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException("elementGetText() function expects text "
                    + "only elment but START_ELEMENT was encountered.", getLocation());
        } else {
            throw new XMLStreamException(
                    "Unexpected event type " + eventType, getLocation());
        }
        eventType = next();
    }
    return content.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:XMLStreamReaderImpl.java

示例12: getElementText

@Override
public final String getElementText() throws XMLStreamException {
	XMLEvent event = this.previousEvent;
	if (event == null) {
		throw new XMLStreamException("Must be on START_ELEMENT to read next text, element was null");
	}
	if (!event.isStartElement()) {
		throw new XMLStreamException("Must be on START_ELEMENT to read next text", event.getLocation());
	}

	final StringBuilder text = new StringBuilder();
	while (!event.isEndDocument()) {
		switch (event.getEventType()) {
			case XMLStreamConstants.CHARACTERS:
			case XMLStreamConstants.SPACE:
			case XMLStreamConstants.CDATA: {
				final Characters characters = event.asCharacters();
				text.append(characters.getData());
				break;
			}
			case XMLStreamConstants.ENTITY_REFERENCE: {
				final EntityReference entityReference = (EntityReference)event;
				final EntityDeclaration declaration = entityReference.getDeclaration();
				text.append(declaration.getReplacementText());
				break;
			}
			case XMLStreamConstants.COMMENT:
			case XMLStreamConstants.PROCESSING_INSTRUCTION: {
				//Ignore
				break;
			}
			default: {
				throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
			}
		}

		event = this.nextEvent();
	}

	return text.toString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:BaseXMLEventReader.java

示例13: parse

public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
    XMLEvent currentEvent = input.peek();
    if (currentEvent != null) {
        int eventType = currentEvent.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT &&
            eventType != XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException();
        }
        fLocationWrapper.setLocation(currentEvent.getLocation());
        fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
        loop: while (input.hasNext()) {
            currentEvent = input.nextEvent();
            eventType = currentEvent.getEventType();
            switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                ++fDepth;
                StartElement start = currentEvent.asStartElement();
                fillQName(fElementQName, start.getName());
                fLocationWrapper.setLocation(start.getLocation());
                fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
                fillXMLAttributes(start);
                fillDeclaredPrefixes(start);
                addNamespaceDeclarations();
                fNamespaceContext.pushContext();
                fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                break;
            case XMLStreamConstants.END_ELEMENT:
                EndElement end = currentEvent.asEndElement();
                fillQName(fElementQName, end.getName());
                fillDeclaredPrefixes(end);
                fLocationWrapper.setLocation(end.getLocation());
                fSchemaDOMParser.endElement(fElementQName, null);
                fNamespaceContext.popContext();
                --fDepth;
                if (fDepth <= 0) {
                    break loop;
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                break;
            case XMLStreamConstants.SPACE:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
                break;
            case XMLStreamConstants.CDATA:
                fSchemaDOMParser.startCDATA(null);
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                fSchemaDOMParser.endCDATA(null);
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                ProcessingInstruction pi = (ProcessingInstruction)currentEvent;
                fillProcessingInstruction(pi.getData());
                fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
                break;
            case XMLStreamConstants.DTD:
                /* There shouldn't be a DTD in the schema */
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                /* Not needed for schemas */
                break;
            case XMLStreamConstants.COMMENT:
                /* No point in sending comments */
                break;
            case XMLStreamConstants.START_DOCUMENT:
                fDepth++;
                /* We automatically call startDocument before the loop */
                break;
            case XMLStreamConstants.END_DOCUMENT:
                /* We automatically call endDocument after the loop */
                break;
            }
        }
        fLocationWrapper.setLocation(null);
        fNamespaceContext.setNamespaceContext(null);
        fSchemaDOMParser.endDocument(null);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:77,代码来源:StAXSchemaParser.java

示例14: printEvent

public static void printEvent(XMLStreamReader xmlr, boolean showEvents) {
  if (showEvents) {
    System.out.print("EVENT:[" + xmlr.getLocation().getLineNumber() + "]["
        + xmlr.getLocation().getColumnNumber() + "] [" + getEventTypeName(xmlr.getEventType())
        + "]");
    System.out.print(" [");
  }
  switch (xmlr.getEventType()) {
    case XMLStreamConstants.START_ELEMENT:
      System.out.print("<");
      printName(xmlr);
      printNamespaces(xmlr);
      printAttributes(xmlr);
      System.out.print(">");
      break;
    case XMLStreamConstants.END_ELEMENT:
      System.out.print("</");
      printName(xmlr);
      System.out.print(">");
      break;
    case XMLStreamConstants.SPACE:
    case XMLStreamConstants.CHARACTERS:
      int start = xmlr.getTextStart();
      int length = xmlr.getTextLength();
      System.out.print(new String(xmlr.getTextCharacters(), start, length));
      break;
    case XMLStreamConstants.PROCESSING_INSTRUCTION:
      System.out.print("<?");
      if (xmlr.hasText())
        System.out.print(xmlr.getText());
      System.out.print("?>");
      break;
    case XMLStreamConstants.CDATA:
      System.out.print("<![CDATA[");
      start = xmlr.getTextStart();
      length = xmlr.getTextLength();
      System.out.print(new String(xmlr.getTextCharacters(), start, length));
      System.out.print("]]>");
      break;
    case XMLStreamConstants.COMMENT:
      System.out.print("<!--");
      if (xmlr.hasText())
        System.out.print(xmlr.getText());
      System.out.print("-->");
      break;
    case XMLStreamConstants.ENTITY_REFERENCE:
      System.out.print(xmlr.getLocalName() + "=");
      if (xmlr.hasText())
        System.out.print("[" + xmlr.getText() + "]");
      break;
    case XMLStreamConstants.START_DOCUMENT:
      System.out.print("<?xml");
      System.out.print(" version='" + xmlr.getVersion() + "'");
      System.out.print(" encoding='" + xmlr.getCharacterEncodingScheme() + "'");
      if (xmlr.isStandalone())
        System.out.print(" standalone='yes'");
      else
        System.out.print(" standalone='no'");
      System.out.print("?>");
      break;
  }
  System.out.println("]");
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:63,代码来源:XMLStreamHelper.java


注:本文中的javax.xml.stream.XMLStreamConstants.PROCESSING_INSTRUCTION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。