use of com.axway.ats.common.xml.XMLException in project ats-framework by Axway.
the class XmlText method removeAttribute.
/**
* Removes an attribute from XML element.
*
* @param xpath XPath , pointing to a XML element
* @param name the name of the attribute
* @return this instance
* @throws XMLException
*/
@PublicAtsApi
public XmlText removeAttribute(String xpath, String name) throws XMLException {
if (StringUtils.isNullOrEmpty(xpath)) {
throw new XMLException("Null/empty xpath is not allowed.");
}
if (StringUtils.isNullOrEmpty(name)) {
throw new XMLException("Null/empty attribute name is not allowed.");
}
Element element = findElement(xpath);
if (element == null) {
throw new XMLException("'" + xpath + "' is not a valid path");
}
Attribute attribute = element.attribute(name);
if (attribute == null) {
throw new XMLException("'" + name + "' attribute cannot be found and replaced for element with xpath '" + xpath + "'.");
}
element.attributes().remove(attribute);
return this;
}
use of com.axway.ats.common.xml.XMLException in project ats-framework by Axway.
the class XmlText method getString.
/**
* @param xpath XPath , pointing to a XML element
* @return a String XML value
* @throws XMLException
*/
@PublicAtsApi
public String getString(String xpath) throws XMLException {
Object object = get(xpath);
Element root = ((XmlText) object).root;
if (root.isTextOnly()) {
object = root.getText().trim();
} else {
throw new XMLException("'" + xpath + "' does not point to a String value:\n" + object.toString());
}
return (String) object;
}
use of com.axway.ats.common.xml.XMLException in project ats-framework by Axway.
the class XmlText method getElementXPaths.
/**
* Returns the child XPaths of a XML element
*
* @return the XPath of the XML element.
* @return the child XPaths of a XML element
* @throws XMLException
*/
@PublicAtsApi
public String[] getElementXPaths(String xpath) throws XMLException {
ArrayList<String> elementXPaths = new ArrayList<>(1);
if (StringUtils.isNullOrEmpty(xpath)) {
throw new XMLException("Null/empty xpath is not allowed.");
}
Element element = findElement(xpath);
if (element == null) {
throw new XMLException("'" + xpath + "' is not a valid path");
}
Iterator<Element> it = element.elementIterator();
while (it.hasNext()) {
elementXPaths.add(it.next().getUniquePath());
}
return elementXPaths.toArray(new String[elementXPaths.size()]);
}
Aggregations