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


Java XmlObject.validate方法代码示例

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


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

示例1: ingestNotification

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
/**
 * Ingests a raw xml by calling ingester
 *
 * @param xml          - XmlObject instance to be inserted
 * @param docType      - Document type
 * @param relationship - Name of the relationship to be ingested, for logging
 * @param type         - Type of the notification
 * @throws IngestException
 */
private void ingestNotification(XmlObject xml, String docType, String relationship,
                                NotificationTypeEnum type) throws IngestException {
    log.debug("Ingesting Raw Notification for " + relationship);
    if (log.isDebugEnabled())
        log.debug(relationship + "Doc:\n" + xml.xmlText(IngesterConstants.PRETTY_PRINT_OPTS));
    // validation errors
    List<XmlError> errors = new ArrayList<XmlError>();
    // if the xml validates properly, store it
    if (xml.validate(new XmlOptions().setErrorListener(errors))) {
        Calendar storeTime = Calendar.getInstance();
        ingester.storeRawNotification(type, storeTime, xml);
    } else {
        log.error(IngesterConstants.EXPMSG_INVALID_NOTIFICATION + docType);
        for (XmlError err : errors) {
            if (err instanceof XmlValidationError) {
                XmlValidationError validationError = (XmlValidationError) err;
                log.error("Message : " + validationError.getMessage());
            }
        }
        throw new IngestException(IngesterConstants.EXPMSG_INVALID_NOTIFICATION + docType);
    }
}
 
开发者ID:Data-to-Insight-Center,项目名称:komadu,代码行数:32,代码来源:BaseDBIngester.java

示例2: validateXml

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
/**
 * <p>Validates the XML, printing error messages when the XML is invalid. Note
 * that this method will properly validate any instance of a compiled schema
 * type because all of these types extend XmlObject.</p>
 *
 * <p>Note that in actual practice, you'll probably want to use an assertion
 * when validating if you want to ensure that your code doesn't pass along
 * invalid XML. This sample prints the generated XML whether or not it's
 * valid so that you can see the result in both cases.</p>
 *
 * @param xml The XML to validate.
 * @return <code>true</code> if the XML is valid; otherwise, <code>false</code>
 */
public static boolean validateXml(XmlObject xml) {
    boolean isXmlValid = false;

    // A collection instance to hold validation error messages.
    ArrayList<XmlError> validationMessages = new ArrayList<XmlError>();

    // Validate the XML, collecting messages.
    isXmlValid = xml.validate(
            new XmlOptions().setErrorListener(validationMessages));

    // If the XML isn't valid, print the messages.
    if (!isXmlValid) {
        System.out.println("\nInvalid XML: ");
        for (int i = 0; i < validationMessages.size(); i++) {
            XmlError error = validationMessages.get(i);
            System.out.println(error.getMessage());
            System.out.println(error.getObjectLocation());
        }
    }
    return isXmlValid;
}
 
开发者ID:52North,项目名称:uncertml-api,代码行数:35,代码来源:XMLParser.java

示例3: validate

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
/**
 * Validates a specified XmlObject along with logging errors if any.
 * 
 * @param xmlObject
 */
public static void validate(XmlObject xmlObject) throws AiravataException {
    XmlOptions validateOptions = new XmlOptions();
    ArrayList errorList = new ArrayList();
    validateOptions.setErrorListener(errorList);

    boolean isValid = xmlObject.validate(validateOptions);
    if (isValid) {
        // Valid
        return;
    }

    // Error
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < errorList.size(); i++) {
        XmlError error = (XmlError) errorList.get(i);
        logger.warn("Message: " + error.getMessage());
        logger.warn("Location of invalid XML: " + error.getCursorLocation().xmlText());
        stringBuilder.append("Message:" + error.getMessage());
        stringBuilder.append("Location of invalid XML: " + error.getCursorLocation().xmlText());
    }
    throw new AiravataException(stringBuilder.toString());
}
 
开发者ID:apache,项目名称:airavata,代码行数:28,代码来源:XMLUtil.java

示例4: validateDocument

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
public boolean validateDocument (XmlObject xmlObject) {
    boolean valid = xmlObject.validate(xmlOptions);
    if (!valid) {
        logger.error(xmlObject.schemaType() + " failed to validate ");
        for (XmlError xmlError : xmlErrors) {
            logger.error(xmlError);
        }
    }
    assertTrue(valid);
    return valid;
}
 
开发者ID:enasequence,项目名称:schema,代码行数:12,代码来源:XMLValidateTest.java


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