The internal structure of a {@link Document} is like a tree. Each embedded object is a new {@code Document}
itself. We traverse the tree until we've arrived at a leaf and retrieve the value from it.
185154
private Object getValue(Document dbObject, String column) {
		Object valueOrNull = MongoHelpers.getValueOrNull( dbObject, column );
		return valueOrNull;
	}
200581
def process(self, content):
        
        log.debug('processing:\n%s', content)
        self.reset()
        if content.tag is None:
            content.tag = content.value.__class__.__name__
        document = Document()
        if isinstance(content.value, Property):
            root = self.node(content)  # root is never used?
            self.append(document, content)
        else:
            self.append(document, content)
        return document.root()
1095975
function () {
            var t = this,
                documentSelection = t.doc.getSelection(),
                node = documentSelection.focusNode,
                text = new XMLSerializer().serializeToString(documentSelection.getRangeAt(0).cloneContents()),
                url,
                title,
                target;

            while (['A', 'DIV'].indexOf(node.nodeName) < 0) {
                node = node.parentNode;
            }

            if (node && node.nodeName === 'A') {
                var $a = $(node);
                text = $a.text();
                url = $a.attr('href');
                if (!t.o.minimalLinks) {
                    title = $a.attr('title');
                    target = $a.attr('target');
                }
                var range = t.doc.createRange();
                range.selectNode(node);
                documentSelection.removeAllRanges();
                documentSelection.addRange(range);
            }

            t.saveRange();

            var options = {
                url: {
                    label: 'URL',
                    required: true,
                    value: url
                },
                text: {
                    label: t.lang.text,
                    value: text
                }
            };
            if (!t.o.minimalLinks) {
                Object.assign(options, {
                    title: {
                        label: t.lang.title,
                        value: title
                    },
                    target: {
                        label: t.lang.target,
                        value: target
                    }
                });
            }

            t.openModalInsert(t.lang.createLink, options, function (v) { // v is value
                var url = t.prependUrlPrefix(v.url);
                if (!url.length) {
                    return false;
                }

                var link = $(['<a href="', url, '">', v.text || v.url, '</a>'].join(''));

                if (!t.o.minimalLinks) {
                    if (v.title.length > 0) {
                        link.attr('title', v.title);
                    }
                    if (v.target.length > 0) {
                        link.attr('target', v.target);
                    }
                }
                t.range.deleteContents();
                t.range.insertNode(link[0]);
                t.syncCode();
                t.$c.trigger('tbwchange');
                return true;
            });
        }
818116
function(doc) {
  // Skip if the function has a name.
  if (doc.name) {
    return doc.name;
  }

  try {
    var node = doc.codeNode;

    // Is this a simple declaration? "var element = function() {".
    if (node.declarations && node.declarations.length) {
      return node.declarations[0].id.name;
    }

    // Is this an expression? "elementFinder.find = function() {".
    if (node.expression) {
      var parts = [];

      /**
       * Recursively create the function name by examining the object property.
       * @param obj Parsed object.
       * @return {string} The name of the function.
       */
      function buildName(obj) {
        if (!obj) {
          return parts.join('.');
        }

        if (obj.property && obj.property.name) {
          parts.unshift(obj.property.name);
        }

        if (obj.object && obj.object.name) {
          parts.unshift(obj.object.name);
        }

        return buildName(obj.object);
      }

      return buildName(node.expression.left);
    }
  } catch (e) {
    console.log('Could not find document name', doc.file, doc.endingLine);
  }
}
530178
function (node) {
        var parent = node;

        while (parent) {
          if (parent.nodeType === 1 && dom.getContentEditable(parent)) {
            return dom.getContentEditable(parent) === "false" ? parent : node;
          }

          parent = parent.parentNode;
        }

        return node;
      }
363893
private ContentStream jcrBinaryContent( Document document ) {
        // pickup node properties
        Document props = document.getDocument("properties").getDocument(JcrLexicon.Namespace.URI);

        // extract binary value and content
        Binary value = props.getBinary("data");

        if (value == null) {
            return null;
        }

        byte[] content = value.getBytes();
        String fileName = props.getString("fileName");
        String mimeType = props.getString("mimeType");

        // wrap with input stream
        ByteArrayInputStream bin = new ByteArrayInputStream(content);
        bin.reset();

        // create content stream
        return new ContentStreamImpl(fileName, BigInteger.valueOf(content.length), mimeType, bin);
    }
635569
public Document doc() throws IOException {
		// if the stream has already been read, use the text format
		InputSource is;
		if (document == null) {
			if (text == null) {
				is = new InputSource(inputStream);
				is.setEncoding(getCharSet().name());
			} else {
				is = new InputSource(new StringReader(text));
			}
			try {
				document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
			} catch (SAXException e) {
				e.printStackTrace();
			} catch (ParserConfigurationException e) {
				e.printStackTrace();
			}
			inputStream.close();
		}
		return document;
	}
34336
final Document getPayloadDocument() throws ParserConfigurationException,
                                             IOException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "getPayloadDocument");

    Document domDoc = null;

    // If we already have a Document cached we don't need to build it again
    if (softRefToDocument != null) {
      domDoc = softRefToDocument.get();
    }

    // Otherwise we'll take the hit of building it, and cache it in a soft reference
    if (domDoc == null) {
      byte[] bytes = getBytes();
      if ((bytes != null) && (bytes.length > 0)) {
        DocumentBuilderFactory domFactory =DocumentBuilderFactory.newInstance();
        // We need to tell the factory that we want it to be namespace aware.
        domFactory.setNamespaceAware(true);
        DocumentBuilder builder = domFactory.newDocumentBuilder();
        InputStream is = new ByteArrayInputStream(bytes);
        try {
          domDoc = builder.parse(is);
          softRefToDocument = new SoftReference<Document>(domDoc);
        }
        catch (SAXException e) {
          // No FFDC code needed
          // This is not really an error - it just means the data is not XML.
          // As the XPath Expression can't evaluate to True we just set the document to null;
          domDoc = null;
        }
      }
      else {
        domDoc = null;
      }
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "getPayloadDocument", domDoc);
    return domDoc;
  }
198851
public void parse(Document document) {
        responsePayLoad = document.getDocumentElement();
        status = responsePayLoad.getAttribute("stat");
        if ("ok".equals(status)) {
            Element photoIdElement = (Element) responsePayLoad.getElementsByTagName("photoid").item(0);
            if (photoIdElement != null) {
                photoId = ((Text) photoIdElement.getFirstChild()).getData();
            } else {
                photoId = null;
            }
            Element ticketIdElement = (Element) responsePayLoad.getElementsByTagName("ticketid").item(0);
            if (ticketIdElement != null) {
                ticketId = ((Text) ticketIdElement.getFirstChild()).getData();
            } else {
                ticketId = null;
            }
        } else {
            Element errElement = (Element) responsePayLoad.getElementsByTagName("err").item(0);
            errorCode = errElement.getAttribute("code");
            errorMessage = errElement.getAttribute("msg");
        }
    }
1288510
@Override
    public Document toDocument() {
        // if (project == null) throw new NullPointerException("No project");
        assert project != null;

        DocumentFactory docFactory = new DocumentFactory();
        Document document = docFactory.createDocument();
        Dom4JXMLOutput treeBuilder = new Dom4JXMLOutput(document);

        try {
            writeXML(treeBuilder);
        } catch (IOException e) {
            // Can't happen
        }
        return document;
    }
1031441
public static BsonDocument copyOfDocument(final BsonDocument document) {
    final BsonDocument newDocument = new BsonDocument();
    for (final Map.Entry<String, BsonValue> kv : document.entrySet()) {
      newDocument.put(kv.getKey(), kv.getValue());
    }
    return newDocument;
  }
717667
private static Node[] _toNodeArray(Document doc, Object o) {
	if (o instanceof Node) return new Node[] { (Node) o };
	// Node[]
	if (o instanceof Node[]) return ((Node[]) o);
	// NamedNodeMap
	else if (o instanceof NamedNodeMap) {
	    NamedNodeMap map = (NamedNodeMap) o;
	    int len = map.getLength();
	    Node[] nodes = new Node[len];
	    for (int i = 0; i < len; i++) {
		nodes[i] = map.item(i);
	    }
	    return nodes;
	}
	// XMLAttributes
	else if (o instanceof XMLAttributes) {
	    return _toNodeArray(doc, ((XMLAttributes) o).toNamedNodeMap());
	}
	// NodeList
	else if (o instanceof NodeList) {
	    NodeList list = (NodeList) o;
	    int len = list.getLength();
	    Node[] nodes = new Node[len];
	    for (int i = 0; i < nodes.length; i++) {
		nodes[i] = list.item(i);
	    }
	    return nodes;
	}
	return null;
    }
182317
private void internalizeDocument(Document document) throws ParseException {
    init();

    // temporarily remove the database listeners
    List<IDatabaseListener> tmpListeners = new ArrayList<>(listeners);
    listeners.clear();

    Hashtable<String, String> keyMap = new Hashtable<>();

    try {
      Element rootElement = document.getRootElement();
      List<Attribute> rootAttrs = rootElement.getAttributes();

      // extract the master language and put all other root element
      // attributes aside
      for (Attribute attribute : rootAttrs) {
        if (MASTER_LANGUAGE_ATTRIBUTE_NAME.equals(attribute.getName())) {
          masterLanguage = attribute.getValue();
        } else {
          additionalRootAttrs.add(attribute);
        }
      }

      // store additional namespaces. the xsi namespace is used for the attribute xsi:noSchemaNamespaceLocation
      for (Object namespace : rootElement.getAdditionalNamespaces()) {
        // The list is not type save, therefore a cast is done
        if (namespace instanceof Namespace) {
          additionalNamespaces.add((Namespace) namespace);
        } else {
          throw new RuntimeException("Namespace List contains Objects that are not of type Namespace");
        }
      }

      if (masterLanguage == null) {
        // since we cannot determine the line numbers in this methods
        // we pass 0 to occuring ParseExceptions
        throw new ParseException("Master language missing.", 0);
      }

      List<Element> textList = rootElement.getChildren(TEXT_ELEMENT_NAME);

      // the validation in here is kind of unnecessary when the xsd is used for validation.
      // however the xsd validation was added later and it cant hurt to doublecheck some things, there might be cases
      // where the xsd cannot be used
      for (Element textElement : textList) {
        String key = textElement.getAttributeValue(KEY_ATTRIBUTE_NAME);
        if (key == null) {
          throw new ParseException("No key found for text.",
              ((LineNumberElement) textElement).getStartLine());
        }

        if (keyMap.containsKey(key)) {
          parseWarnings.add(new ParseWarning("Duplicate key: " + key,
              ((LineNumberElement) textElement).getStartLine()));
        } else {
          keyMap.put(key, "");
        }

        String context = textElement.getChildText(CONTEXT_ELEMENT_NAME);
        if (context == null) {
          throw new ParseException("No context found for key \"" + key + "\".",
              ((LineNumberElement) textElement).getStartLine());
        }

        ITextNode textNode = new XMLTextNode(key, context);
        addTextNode(textNode);

        List<Element> valueList = textElement.getChildren(VALUE_ELEMENT_NAME);
        for (Element valueElement : valueList) {
          String language = valueElement.getAttributeValue(LANGUAGE_ATTRIBUTE_NAME);
          if (language == null) {
            throw new ParseException("No language found for value of key \"" + key + "\".",
                ((LineNumberElement) valueElement).getStartLine());
          }
          String statusName = valueElement.getAttributeValue(STATUS_ATTRIBUTE_NAME);
          Status status = Status.valueOf(statusName);
          if (status == null) {
            throw new ParseException("Invalid status for key \"" + key + "\": " + statusName,
                ((LineNumberElement) valueElement).getStartLine());
          }
          String value = valueElement.getText();
          textNode.addValueNode(new XMLValueNode(language, status, value));
        }
      }
    } finally {
      listeners.addAll(tmpListeners);
    }
  }
767644
@Override
    public Document createDocument(Document parentDocument) {
        Ruby runtime = JRubyRuntimeContext.get(parentDocument);
        RubyHash options = RubyHash.newHash(runtime);
        options.put(
                runtime.newSymbol("parent"),
                ((DocumentImpl) parentDocument).getRubyObject());

        return (Document) NodeConverter.createASTNode(runtime, NodeConverter.NodeType.DOCUMENT_CLASS, runtime.getNil(), options);
    }
765979
public Node cloneNode(boolean deep) {
        try {
            if (isXMLDoc == UNKNOWN_TYPE) isXMLDoc = getDocumentType();
            if (isXMLDoc == NON_XML) {
                throw new UnsupportedOperationException(
                    "Text document cannot be cloned");
            }
            // initialize a new doc owner node
            initClonedOwnerDoc();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("Internal Error:" + e);
        }
        if (deep) {
            for (NodeImpl n = (NodeImpl) getFirstChild(); n != null; n = (NodeImpl) n
                .getNextSibling()) {
                ownerDocCloned.appendChild(n.cloneNode(ownerDocCloned, true));
            }
        }
        return ownerDocCloned;
    }
779479
public static Document getOwnerDocument(Node n) {
    return n == null || !isElement(n) ? null : n.getNodeType() == Node.DOCUMENT_NODE
        ? n.<Document> cast() : n.getOwnerDocument();
  }
255857
@SafeVarargs
    public static Document toDocument(final Object... a) {
        if (N.isNullOrEmpty(a)) {
            return new Document();
        }

        return a.length == 1 ? toDocument(a[0]) : toDocument((Object) a);
    }