use of org.w3c.dom.Attr in project robovm by robovm.
the class DOM3TreeWalker method isAttributeWellFormed.
/**
* Checks if an attr node is well-formed, by checking it's Name and value
* for well-formedness.
*
* @param data The contents of the comment node
* @return a boolean indiacating if the comment is well-formed or not.
*/
protected void isAttributeWellFormed(Node node) {
boolean isNameWF = false;
if ((fFeatures & NAMESPACES) != 0) {
isNameWF = isValidQName(node.getPrefix(), node.getLocalName(), fIsXMLVersion11);
} else {
isNameWF = isXMLName(node.getNodeName(), fIsXMLVersion11);
}
if (!isNameWF) {
String msg = Utils.messages.createMessage(MsgKey.ER_WF_INVALID_CHARACTER_IN_NODE_NAME, new Object[] { "Attr", node.getNodeName() });
if (fErrorHandler != null) {
fErrorHandler.handleError(new DOMErrorImpl(DOMError.SEVERITY_FATAL_ERROR, msg, MsgKey.ER_WF_INVALID_CHARACTER_IN_NODE_NAME, null, null, null));
}
}
// Check the Attr's node value
// WFC: No < in Attribute Values
String value = node.getNodeValue();
if (value.indexOf('<') >= 0) {
String msg = Utils.messages.createMessage(MsgKey.ER_WF_LT_IN_ATTVAL, new Object[] { ((Attr) node).getOwnerElement().getNodeName(), node.getNodeName() });
if (fErrorHandler != null) {
fErrorHandler.handleError(new DOMErrorImpl(DOMError.SEVERITY_FATAL_ERROR, msg, MsgKey.ER_WF_LT_IN_ATTVAL, null, null, null));
}
}
// we need to loop through the children of attr nodes and check their values for
// well-formedness
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
// should have some exception defined for this.
if (child == null) {
// we should probably report an error
continue;
}
switch(child.getNodeType()) {
case Node.TEXT_NODE:
isTextWellFormed((Text) child);
break;
case Node.ENTITY_REFERENCE_NODE:
isEntityReferneceWellFormed((EntityReference) child);
break;
default:
}
}
// TODO:
// WFC: Check if the attribute prefix is bound to
// http://www.w3.org/2000/xmlns/
// WFC: Unique Att Spec
// Perhaps pass a seen boolean value to this method. serializeAttList will determine
// if the attr was seen before.
}
use of org.w3c.dom.Attr in project robovm by robovm.
the class XsltXPathConformanceTestSuite method emitAttributes.
private void emitAttributes(XmlSerializer serializer, Node node) throws IOException {
NamedNodeMap map = node.getAttributes();
if (map == null) {
return;
}
List<Attr> attributes = new ArrayList<Attr>();
for (int i = 0; i < map.getLength(); i++) {
attributes.add((Attr) map.item(i));
}
Collections.sort(attributes, orderByName);
for (Attr attr : attributes) {
if ("xmlns".equals(attr.getPrefix()) || "xmlns".equals(attr.getLocalName())) {
/*
* Omit namespace declarations because they aren't considered
* data. Ie. <foo:a xmlns:bar="http://google.com"> is semantically
* equal to <bar:a xmlns:bar="http://google.com"> since the
* prefix doesn't matter, only the URI it points to.
*
* When we omit the prefix, our XML serializer will still
* generate one for us, using a predictable pattern.
*/
} else {
serializer.attribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getValue());
}
}
}
use of org.w3c.dom.Attr in project robovm by robovm.
the class AttrGetOwnerElement method testGetOwnerElement5.
public void testGetOwnerElement5() throws Throwable {
Document doc;
Node element;
Element ownerElement;
Element parentElement;
NodeList elementList;
String ownerElementName;
Attr attr;
NamedNodeMap nodeMap;
String nullNS = null;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagNameNS("*", "address");
element = elementList.item(1);
parentElement = (Element) element.getParentNode();
nodeMap = element.getAttributes();
parentElement.removeChild(element);
attr = (Attr) nodeMap.getNamedItemNS(nullNS, "street");
ownerElement = attr.getOwnerElement();
ownerElementName = ownerElement.getNodeName();
assertEquals("attrgetownerelement05", "address", ownerElementName);
}
use of org.w3c.dom.Attr in project robovm by robovm.
the class AttrGetOwnerElement method testGetOwnerElement4.
public void testGetOwnerElement4() throws Throwable {
Document doc;
Document docImp;
Node ownerElement;
Element element;
Attr attr;
Attr attrImp;
NodeList addresses;
doc = (Document) load("staffNS", builder);
docImp = (Document) load("staff", builder);
addresses = doc.getElementsByTagNameNS("http://www.nist.gov", "address");
element = (Element) addresses.item(1);
assertNotNull("empAddressNotNull", element);
attr = element.getAttributeNodeNS("http://www.nist.gov", "zone");
attrImp = (Attr) docImp.importNode(attr, true);
ownerElement = attrImp.getOwnerElement();
assertNull("attrgetownerelement04", ownerElement);
}
use of org.w3c.dom.Attr in project robovm by robovm.
the class DocumentImportNode method testImportNode2.
/**
* Runs the test case.
*
* @throws Throwable
* Any uncaught exception causes test to fail
*/
// Assumes validation.
// public void testImportNode1() throws Throwable {
// Document doc;
// Element element;
// Attr attr;
// NodeList childList;
// Node importedAttr;
// String nodeName;
// int nodeType;
// String nodeValue;
// doc = (Document) load("staffNS", builder);
// childList = doc
// .getElementsByTagNameNS("http://www.nist.gov", "address");
// element = (Element) childList.item(1);
// attr = element.getAttributeNode("street");
// importedAttr = doc.importNode(attr, false);
// nodeName = importedAttr.getNodeName();
// nodeValue = importedAttr.getNodeValue();
// nodeType = (int) importedAttr.getNodeType();
// assertEquals("documentimportnode01_nodeName", "street", nodeName);
// assertEquals("documentimportnode01_nodeType", 2, nodeType);
// assertEquals("documentimportnode01_nodeValue", "Yes", nodeValue);
// }
public void testImportNode2() throws Throwable {
Document doc;
Document docImported;
Element element;
Attr attr;
Node importedAttr;
String nodeName;
int nodeType;
String nodeValue;
NodeList addresses;
Node attrsParent;
doc = (Document) load("staffNS", builder);
docImported = (Document) load("staff", builder);
addresses = doc.getElementsByTagNameNS("http://www.nist.gov", "address");
element = (Element) addresses.item(1);
attr = element.getAttributeNodeNS("http://www.nist.gov", "zone");
importedAttr = docImported.importNode(attr, false);
nodeName = importedAttr.getNodeName();
nodeType = (int) importedAttr.getNodeType();
nodeValue = importedAttr.getNodeValue();
attrsParent = importedAttr.getParentNode();
assertNull("documentimportnode02_parentNull", attrsParent);
assertEquals("documentimportnode02_nodeName", "emp:zone", nodeName);
assertEquals("documentimportnode02_nodeType", 2, nodeType);
assertEquals("documentimportnode02_nodeValue", "CANADA", nodeValue);
}
Aggregations