Skip to content

Instantly share code, notes, and snippets.

@magicliang
Created January 7, 2020 07:22
Show Gist options
  • Save magicliang/e911cff65791d7ddf06b782d4c9bf154 to your computer and use it in GitHub Desktop.
Save magicliang/e911cff65791d7ddf06b782d4c9bf154 to your computer and use it in GitHub Desktop.
spring的DefaultBeanDefinitionDocumentReader解析xml得到资源的解法
/**
* Parse the elements at the root level in the document:
* "import", "alias", "bean".
* @param root the DOM root element of the document
*/
protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate) {
if (delegate.isDefaultNamespace(root)) {
NodeList nl = root.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element ele = (Element) node;
if (delegate.isDefaultNamespace(ele)) {
parseDefaultElement(ele, delegate);
}
else {
delegate.parseCustomElement(ele);
}
}
}
}
else {
delegate.parseCustomElement(root);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment