use of nokogiri.XmlNamespace in project gocd by gocd.
the class NokogiriHelpers method getCachedNodeOrCreate.
/**
* Get the XmlNode associated with the underlying
* <code>node</code>. Creates a new XmlNode (or appropriate subclass)
* or XmlNamespace wrapping <code>node</code> if there is no cached
* value.
*/
public static IRubyObject getCachedNodeOrCreate(Ruby ruby, Node node) {
if (node == null)
return ruby.getNil();
if (node.getNodeType() == Node.ATTRIBUTE_NODE && isNamespace(node.getNodeName())) {
XmlDocument xmlDocument = (XmlDocument) node.getOwnerDocument().getUserData(CACHED_NODE);
if (!(xmlDocument instanceof HtmlDocument)) {
String prefix = getLocalNameForNamespace(((Attr) node).getName());
prefix = prefix != null ? prefix : "";
String href = ((Attr) node).getValue();
XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefix, href);
if (xmlNamespace != null)
return xmlNamespace;
else
return XmlNamespace.createFromAttr(ruby, (Attr) node);
}
}
XmlNode xmlNode = getCachedNode(node);
if (xmlNode == null) {
xmlNode = (XmlNode) constructNode(ruby, node);
node.setUserData(CACHED_NODE, xmlNode, null);
}
return xmlNode;
}
use of nokogiri.XmlNamespace in project nokogiri by sparklemotion.
the class NokogiriHelpers method getCachedNodeOrCreate.
/**
* Get the XmlNode associated with the underlying
* <code>node</code>. Creates a new XmlNode (or appropriate subclass)
* or XmlNamespace wrapping <code>node</code> if there is no cached
* value.
*/
public static IRubyObject getCachedNodeOrCreate(Ruby ruby, Node node) {
if (node == null)
return ruby.getNil();
if (node.getNodeType() == Node.ATTRIBUTE_NODE && isNamespace(node.getNodeName())) {
XmlDocument xmlDocument = (XmlDocument) node.getOwnerDocument().getUserData(CACHED_NODE);
if (!(xmlDocument instanceof HtmlDocument)) {
String prefix = getLocalNameForNamespace(((Attr) node).getName());
prefix = prefix != null ? prefix : "";
String href = ((Attr) node).getValue();
XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefix, href);
if (xmlNamespace != null)
return xmlNamespace;
else
return XmlNamespace.createFromAttr(ruby, (Attr) node);
}
}
XmlNode xmlNode = getCachedNode(node);
if (xmlNode == null) {
xmlNode = (XmlNode) constructNode(ruby, node);
node.setUserData(CACHED_NODE, xmlNode, null);
}
return xmlNode;
}
Aggregations