]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/XmlRoutines.py
Sync BaseTool trunk (version r2423) into EDKII BaseTools. The change mainly includes:
[mirror_edk2.git] / BaseTools / Source / Python / Common / XmlRoutines.py
diff --git a/BaseTools/Source/Python/Common/XmlRoutines.py b/BaseTools/Source/Python/Common/XmlRoutines.py
deleted file mode 100644 (file)
index 5823067..0000000
+++ /dev/null
@@ -1,228 +0,0 @@
-## @file\r
-# This is an XML API that uses a syntax similar to XPath, but it is written in\r
-# standard python so that no extra python packages are required to use it.\r
-#\r
-# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution.  The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-\r
-##\r
-# Import Modules\r
-#\r
-import xml.dom.minidom\r
-\r
-## Create a element of XML\r
-#\r
-# @param Name\r
-# @param String\r
-# @param NodeList\r
-# @param AttributeList\r
-#\r
-# @revel Element\r
-#\r
-def CreateXmlElement(Name, String, NodeList, AttributeList):\r
-    Doc = xml.dom.minidom.Document()\r
-    Element = Doc.createElement(Name)\r
-    if String != '' and String != None:\r
-        Element.appendChild(Doc.createTextNode(String))\r
-    \r
-    for Item in NodeList:\r
-        if type(Item) == type([]):\r
-            Key = Item[0]\r
-            Value = Item[1]\r
-            if Key != '' and Key != None and Value != '' and Value != None:\r
-                Node = Doc.createElement(Key)\r
-                Node.appendChild(Doc.createTextNode(Value))\r
-                Element.appendChild(Node)\r
-        else:\r
-            Element.appendChild(Item)\r
-    for Item in AttributeList:\r
-        Key = Item[0]\r
-        Value = Item[1]\r
-        if Key != '' and Key != None and Value != '' and Value != None:\r
-            Element.setAttribute(Key, Value)\r
-    \r
-    return Element\r
-\r
-## Get a list of XML nodes using XPath style syntax.\r
-#\r
-# Return a list of XML DOM nodes from the root Dom specified by XPath String.\r
-# If the input Dom or String is not valid, then an empty list is returned.\r
-#\r
-# @param  Dom                The root XML DOM node.\r
-# @param  String             A XPath style path.\r
-#\r
-# @revel  Nodes              A list of XML nodes matching XPath style Sting.\r
-#\r
-def XmlList(Dom, String):\r
-    if String == None or String == "" or Dom == None or Dom == "":\r
-        return []\r
-    if Dom.nodeType == Dom.DOCUMENT_NODE:\r
-        Dom = Dom.documentElement\r
-    if String[0] == "/":\r
-        String = String[1:]\r
-    TagList = String.split('/')\r
-    Nodes = [Dom]\r
-    Index = 0\r
-    End = len(TagList) - 1\r
-    while Index <= End:\r
-        ChildNodes = []\r
-        for Node in Nodes:\r
-            if Node.nodeType == Node.ELEMENT_NODE and Node.tagName == TagList[Index]:\r
-                if Index < End:\r
-                    ChildNodes.extend(Node.childNodes)\r
-                else:\r
-                    ChildNodes.append(Node)\r
-        Nodes = ChildNodes\r
-        ChildNodes = []\r
-        Index += 1\r
-\r
-    return Nodes\r
-\r
-\r
-## Get a single XML node using XPath style syntax.\r
-#\r
-# Return a single XML DOM node from the root Dom specified by XPath String.\r
-# If the input Dom or String is not valid, then an empty string is returned.\r
-#\r
-# @param  Dom                The root XML DOM node.\r
-# @param  String             A XPath style path.\r
-#\r
-# @revel  Node               A single XML node matching XPath style Sting.\r
-#\r
-def XmlNode(Dom, String):\r
-    if String == None or String == ""  or Dom == None or Dom == "":\r
-        return ""\r
-    if Dom.nodeType == Dom.DOCUMENT_NODE:\r
-        Dom = Dom.documentElement\r
-    if String[0] == "/":\r
-        String = String[1:]\r
-    TagList = String.split('/')\r
-    Index = 0\r
-    End = len(TagList) - 1\r
-    ChildNodes = [Dom]\r
-    while Index <= End:\r
-        for Node in ChildNodes:\r
-            if Node.nodeType == Node.ELEMENT_NODE and Node.tagName == TagList[Index]:\r
-                if Index < End:\r
-                    ChildNodes = Node.childNodes\r
-                else:\r
-                    return Node\r
-                break\r
-        Index += 1\r
-    return ""\r
-\r
-\r
-## Get a single XML element using XPath style syntax.\r
-#\r
-# Return a single XML element from the root Dom specified by XPath String.\r
-# If the input Dom or String is not valid, then an empty string is returned.\r
-#\r
-# @param  Dom                The root XML DOM object.\r
-# @param  Strin              A XPath style path.\r
-#\r
-# @revel  Element            An XML element matching XPath style Sting.\r
-#\r
-def XmlElement(Dom, String):\r
-    try:\r
-        return XmlNode(Dom, String).firstChild.data.strip()\r
-    except:\r
-        return ""\r
-\r
-\r
-## Get a single XML element of the current node.\r
-#\r
-# Return a single XML element specified by the current root Dom.\r
-# If the input Dom is not valid, then an empty string is returned.\r
-#\r
-# @param  Dom                The root XML DOM object.\r
-#\r
-# @revel  Element            An XML element in current root Dom.\r
-#\r
-def XmlElementData(Dom):\r
-    try:\r
-        return Dom.firstChild.data.strip()\r
-    except:\r
-        return ""\r
-\r
-\r
-## Get a list of XML elements using XPath style syntax.\r
-#\r
-# Return a list of XML elements from the root Dom specified by XPath String.\r
-# If the input Dom or String is not valid, then an empty list is returned.\r
-#\r
-# @param  Dom                The root XML DOM object.\r
-# @param  String             A XPath style path.\r
-#\r
-# @revel  Elements           A list of XML elements matching XPath style Sting.\r
-#\r
-def XmlElementList(Dom, String):\r
-    return map(XmlElementData, XmlList(Dom, String))\r
-\r
-\r
-## Get the XML attribute of the current node.\r
-#\r
-# Return a single XML attribute named Attribute from the current root Dom.\r
-# If the input Dom or Attribute is not valid, then an empty string is returned.\r
-#\r
-# @param  Dom                The root XML DOM object.\r
-# @param  Attribute          The name of Attribute.\r
-#\r
-# @revel  Element            A single XML element matching XPath style Sting.\r
-#\r
-def XmlAttribute(Dom, Attribute):\r
-    try:\r
-        return Dom.getAttribute(Attribute).strip()\r
-    except:\r
-        return ''\r
-\r
-\r
-## Get the XML node name of the current node.\r
-#\r
-# Return a single XML node name from the current root Dom.\r
-# If the input Dom is not valid, then an empty string is returned.\r
-#\r
-# @param  Dom                The root XML DOM object.\r
-#\r
-# @revel  Element            A single XML element matching XPath style Sting.\r
-#\r
-def XmlNodeName(Dom):\r
-    try:\r
-        return Dom.nodeName.strip()\r
-    except:\r
-        return ''\r
-\r
-## Parse an XML file.\r
-#\r
-# Parse the input XML file named FileName and return a XML DOM it stands for.\r
-# If the input File is not a valid XML file, then an empty string is returned.\r
-#\r
-# @param  FileName           The XML file name.\r
-#\r
-# @revel  Dom                The Dom object achieved from the XML file.\r
-#\r
-def XmlParseFile(FileName):\r
-    try:\r
-        XmlFile = open(FileName)\r
-        Dom = xml.dom.minidom.parse(XmlFile)\r
-        XmlFile.close()\r
-        return Dom\r
-    except Exception, X:\r
-        print X\r
-        return ""\r
-\r
-# This acts like the main() function for the script, unless it is 'import'ed\r
-# into another script.\r
-if __name__ == '__main__':\r
-    # Nothing to do here. Could do some unit tests.\r
-    A = CreateXmlElement('AAA', 'CCC',  [['AAA', '111'], ['BBB', '222']], [['A', '1'], ['B', '2']])\r
-    B = CreateXmlElement('ZZZ', 'CCC',  [['XXX', '111'], ['YYY', '222']], [['A', '1'], ['B', '2']])\r
-    C = CreateXmlList('DDD', 'EEE', [A, B], ['FFF', 'GGG'])\r
-    print C.toprettyxml(indent = " ")\r
-    pass\r