diff options
author | bbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-01-20 00:41:32 +0000 |
---|---|---|
committer | bbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-01-20 00:41:32 +0000 |
commit | 4040421aeed0f34fe2e039dafc1e1312dfa3e6a9 (patch) | |
tree | de92fe08b68651121729eef752c4822b98276ead /Tools/Python/XmlRoutines.py | |
parent | caea5554abdc29d7774bdd0ec4852be09d5a1630 (diff) | |
download | edk2-platforms-4040421aeed0f34fe2e039dafc1e1312dfa3e6a9.tar.xz |
Add a program to install fars.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2276 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Tools/Python/XmlRoutines.py')
-rwxr-xr-x | Tools/Python/XmlRoutines.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Tools/Python/XmlRoutines.py b/Tools/Python/XmlRoutines.py index 53f5aa8f61..0345f4acc6 100755 --- a/Tools/Python/XmlRoutines.py +++ b/Tools/Python/XmlRoutines.py @@ -16,12 +16,12 @@ import xml.dom.minidom def XmlList(Dom, String): """Get a list of XML Elements using XPath style syntax.""" + if String == "" : + return [] if Dom.nodeType==Dom.DOCUMENT_NODE: return XmlList(Dom.documentElement, String) if String[0] == "/": return XmlList(Dom, String[1:]) - if String == "" : - return [] TagList = String.split('/') nodes = [] if Dom.nodeType == Dom.ELEMENT_NODE and Dom.tagName.strip() == TagList[0]: @@ -33,6 +33,14 @@ def XmlList(Dom, String): nodes = nodes + XmlList(child, restOfPath) return nodes +def XmlNode (Dom, String): + """Return a single node that matches the String which is XPath style syntax.""" + try: + return XmlList (Dom, String)[0] + except: + return None + + def XmlElement (Dom, String): """Return a single element that matches the String which is XPath style syntax.""" try: @@ -88,6 +96,19 @@ def XmlParseFileSection (FileName, Tag): except: return xml.dom.minidom.parseString('<empty/>') +def XmlParseStringSection (XmlString, Tag): + """Parse a section of an XML string into a DOM(Document Object Model) and return the DOM.""" + Start = '<' + Tag + End = '</' + Tag + '>' + File = XmlString + if File.find(Start) < 0 or File.find(End) < 0: + return xml.dom.minidom.parseString('<empty/>') + File = File[File.find(Start):File.find(End)+len(End)] + try: + return xml.dom.minidom.parseString(File) + except: + return xml.dom.minidom.parseString('<empty/>') + def XmlSaveFile (Dom, FileName, Encoding='UTF-8'): """Save a DOM(Document Object Model) into an XML file.""" try: |