use of org.w3c.dom.Attr in project hackpad by dropbox.
the class XmlNode method deleteMe.
void deleteMe() {
if (dom instanceof Attr) {
Attr attr = (Attr) this.dom;
attr.getOwnerElement().getAttributes().removeNamedItemNS(attr.getNamespaceURI(), attr.getLocalName());
} else {
if (this.dom.getParentNode() != null) {
this.dom.getParentNode().removeChild(this.dom);
} else {
// This case can be exercised at least when executing the regression
// tests under https://bugzilla.mozilla.org/show_bug.cgi?id=354145
}
}
}
use of org.w3c.dom.Attr in project che by eclipse.
the class Element method createAttrNSNode.
private Attr createAttrNSNode(NewAttribute attribute) {
if (attribute.getPrefix().equals(XMLNS_ATTRIBUTE)) {
final Attr attr = document().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, attribute.getName());
attr.setValue(attribute.getValue());
//save uri
xmlTree.putNamespace(attribute.getLocalName(), attribute.getValue());
return attr;
} else {
//retrieve namespace
final String uri = xmlTree.getNamespaceUri(attribute.getPrefix());
final Attr attr = document().createAttributeNS(uri, attribute.getName());
attr.setValue(attribute.getValue());
return attr;
}
}
use of org.w3c.dom.Attr in project che by eclipse.
the class RefactoringSessionTransformer method createArgument.
/**
* Creates a refactoring argument with the specified name and value.
* <p>
* If no refactoring is currently processed, this call has no effect.
* </p>
*
* @param name
* the non-empty name of the argument
* @param value
* the value of the argument
*
* @throws CoreException
* if an error occurs while creating a new argument
*/
public void createArgument(final String name, final String value) throws CoreException {
Assert.isNotNull(name);
//$NON-NLS-1$
Assert.isTrue(!"".equals(name));
Assert.isNotNull(value);
if (fDocument != null && fRefactoringArguments != null && value != null) {
try {
final Attr attribute = fDocument.createAttribute(name);
attribute.setValue(value);
fRefactoringArguments.add(attribute);
} catch (DOMException exception) {
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, exception.getLocalizedMessage(), null));
}
}
}
use of org.w3c.dom.Attr in project orientdb by orientechnologies.
the class OXmlExtractor method xml2doc.
private Object xml2doc(final Node xmlDocument, final String iPath, final int iLevel) {
final ODocument doc = new ODocument();
Object result = doc;
final NamedNodeMap attrs = xmlDocument.getAttributes();
if (attrs != null)
for (int i = 0; i < attrs.getLength(); ++i) {
final Node item = attrs.item(i);
switch(item.getNodeType()) {
case Node.ATTRIBUTE_NODE:
{
final Attr attr = (Attr) item;
doc.field(attr.getName(), attr.getValue());
break;
}
}
}
final NodeList children = xmlDocument.getChildNodes();
if (children != null) {
for (int i = 0; i < children.getLength(); ++i) {
final Node child = children.item(i);
switch(child.getNodeType()) {
case Node.ELEMENT_NODE:
{
final Element element = (Element) child;
final String path = iPath.isEmpty() ? element.getNodeName() : iPath + "." + element.getNodeName();
if (tagsAsAttribute.contains(iPath)) {
final NodeList subChildren = element.getChildNodes();
if (subChildren.getLength() > 0) {
final Node fieldContent = subChildren.item(0);
doc.field(element.getNodeName(), fieldContent.getTextContent());
}
} else {
final Object sub = xml2doc(element, path, iLevel + 1);
final Object previous = doc.field(element.getNodeName());
if (previous != null) {
List list;
if (previous instanceof List) {
list = (List) previous;
} else {
// TRANSFORM IN A LIST
list = new ArrayList();
list.add(previous);
doc.field(element.getNodeName(), list, OType.EMBEDDEDLIST);
}
list.add(sub);
} else
doc.field(element.getNodeName(), sub, OType.EMBEDDED);
if (rootNode != null && rootNode.startsWith(path))
// SKIP
result = doc.field(element.getNodeName());
}
break;
}
}
}
}
return result;
}
use of org.w3c.dom.Attr in project midpoint by Evolveum.
the class DomLexicalProcessor method parseElementContentToMap.
private MapXNode parseElementContentToMap(Element element) throws SchemaException {
MapXNode xmap = new MapXNode();
// Attributes
for (Attr attr : DOMUtil.listApplicationAttributes(element)) {
QName attrQName = DOMUtil.getQName(attr);
XNode subnode = parseAttributeValue(attr);
xmap.put(attrQName, subnode);
}
// Sub-elements
QName lastElementQName = null;
List<Element> lastElements = null;
for (Element childElement : DOMUtil.listChildElements(element)) {
QName childQName = DOMUtil.getQName(childElement);
if (match(childQName, lastElementQName)) {
lastElements.add(childElement);
} else {
parseSubElementsGroupAsMapEntry(xmap, lastElementQName, lastElements);
lastElementQName = childQName;
lastElements = new ArrayList<>();
lastElements.add(childElement);
}
}
parseSubElementsGroupAsMapEntry(xmap, lastElementQName, lastElements);
return xmap;
}
Aggregations