gpt4 book ai didi

org.codehaus.cargo.util.XmlUtils.selectElementMatchingXPath()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 22:24:40 26 4
gpt4 key购买 nike

本文整理了Java中org.codehaus.cargo.util.XmlUtils.selectElementMatchingXPath()方法的一些代码示例,展示了XmlUtils.selectElementMatchingXPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlUtils.selectElementMatchingXPath()方法的具体详情如下:
包路径:org.codehaus.cargo.util.XmlUtils
类名称:XmlUtils
方法名:selectElementMatchingXPath

XmlUtils.selectElementMatchingXPath介绍

[英]The following will search the given element for the specified XPath and return any node that matches.
[中]下面将在给定元素中搜索指定的XPath,并返回任何匹配的节点。

代码示例

代码示例来源:origin: codehaus-cargo/cargo

/**
 * {@inheritDoc}
 */
@Override
public void insertElementUnderXPath(Element elementToInsert, String xpath)
{
  Element parent = xmlUtil.selectElementMatchingXPath(xpath, document.getDocumentElement());
  Node clone = parent.getOwnerDocument().importNode(elementToInsert, true);
  parent.appendChild(clone);
}

代码示例来源:origin: org.codehaus.cargo/cargo-core-api-util

/**
 * {@inheritDoc}
 */
@Override
public void insertElementUnderXPath(Element elementToInsert, String xpath)
{
  Element parent = xmlUtil.selectElementMatchingXPath(xpath, document.getDocumentElement());
  Node clone = parent.getOwnerDocument().importNode(elementToInsert, true);
  parent.appendChild(clone);
}

代码示例来源:origin: org.codehaus.cargo/cargo-core-api-util

/**
 * {@inheritDoc}
 */
@Override
public void insertElementsUnderXPath(String elementsToParse, String xpath)
{
  Element parent = xmlUtil.selectElementMatchingXPath(xpath, document.getDocumentElement());
  StringBuilder nested = new StringBuilder();
  nested.append("<parent>");
  nested.append(elementsToParse);
  nested.append("</parent>");
  Element nestedElements = xmlUtil.parseIntoElement(nested.toString());
  NodeList children = nestedElements.getChildNodes();
  for (int i = 0; i < children.getLength(); i++)
  {
    Node child = children.item(i);
    Node clone = parent.getOwnerDocument().importNode(child, true);
    parent.appendChild(clone);
  }
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * {@inheritDoc}
 */
@Override
public void insertElementsUnderXPath(String elementsToParse, String xpath)
{
  Element parent = xmlUtil.selectElementMatchingXPath(xpath, document.getDocumentElement());
  StringBuilder nested = new StringBuilder();
  nested.append("<parent>");
  nested.append(elementsToParse);
  nested.append("</parent>");
  Element nestedElements = xmlUtil.parseIntoElement(nested.toString());
  NodeList children = nestedElements.getChildNodes();
  for (int i = 0; i < children.getLength(); i++)
  {
    Node child = children.item(i);
    Node clone = parent.getOwnerDocument().importNode(child, true);
    parent.appendChild(clone);
  }
}

代码示例来源:origin: org.codehaus.cargo/cargo-core-container-weblogic

xmlTool.selectElementMatchingXPath("weblogic:configuration-version", domain);
Node before = null;
NodeList children = domain.getChildNodes();

代码示例来源:origin: codehaus-cargo/cargo

xmlTool.selectElementMatchingXPath("weblogic:configuration-version", domain);
Node before = null;
NodeList children = domain.getChildNodes();

代码示例来源:origin: codehaus-cargo/cargo

/**
   * Test simple element parse.
   * @throws Exception If anything does wrong.
   */
  public void testSelectElementMatchingXPath() throws Exception
  {
    Map<String, String> namespace = new HashMap<String, String>();
    namespace.put("animal", "urn:animal");
    util.setNamespaces(namespace);

    String string = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
        + "<base-element>"
        + "<element>dog</element>"
        + "<element xmlns=\"urn:animal\">cat</element>"
        + "</base-element>";
    Element element = util.parseIntoElement(string);
    Element animalElement = util.selectElementMatchingXPath("//base-element/animal:element",
        element);

    assertEquals("element", animalElement.getNodeName());
    assertEquals("cat", animalElement.getTextContent());
  }
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test that search for a non-existing element throws an exception.
 */
public void testNoElementThrowsException()
{
  try
  {
    util.selectElementMatchingXPath("app-deployment", testElement);
    fail("should have thrown an exception");
  }
  catch (ElementNotFoundException e)
  {
    assertEquals(testElement, e.getSearched());
  }
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test that search for a non-existing element throws an exception.
 */
public void testNoNamespaceThrowsException()
{
  String xPath = "weblogic:app-deployment";
  try
  {
    util.selectElementMatchingXPath(xPath, testElement);
    fail("should have thrown an exception");
  }
  catch (CargoException e)
  {
    assertEquals("Cannot evaluate XPath: " + xPath, e.getMessage());
  }
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * {@inheritDoc} deploys files by adding their configuration to the config.xml file of the
 * WebLogic server.
 */
@Override
public void deploy(Deployable deployable)
{
  XmlUtils xmlUtil = new XmlUtils(getFileHandler());
  Document configXml =
    xmlUtil.loadXmlFromFile(getFileHandler().append(getDomainHome(), "config.xml"));
  Element domain = xmlUtil.selectElementMatchingXPath("//Domain",
    configXml.getDocumentElement());
  if (deployable.getType() == DeployableType.WAR)
  {
    addWarToDomain((WAR) deployable, domain);
  }
  else if (deployable.getType() == DeployableType.EAR)
  {
    addEarToDomain((EAR) deployable, domain);
  }
  else
  {
    throw new ContainerException("Not supported");
  }
  this.writeConfigXml(configXml);
}

代码示例来源:origin: org.codehaus.cargo/cargo-core-container-weblogic

/**
 * {@inheritDoc} deploys files by adding their configuration to the config.xml file of the
 * WebLogic server.
 */
@Override
public void deploy(Deployable deployable)
{
  XmlUtils xmlUtil = new XmlUtils(getFileHandler());
  Document configXml =
    xmlUtil.loadXmlFromFile(getFileHandler().append(getDomainHome(), "config.xml"));
  Element domain = xmlUtil.selectElementMatchingXPath("//Domain",
    configXml.getDocumentElement());
  if (deployable.getType() == DeployableType.WAR)
  {
    addWarToDomain((WAR) deployable, domain);
  }
  else if (deployable.getType() == DeployableType.EAR)
  {
    addEarToDomain((EAR) deployable, domain);
  }
  else
  {
    throw new ContainerException("Not supported");
  }
  this.writeConfigXml(configXml);
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com