XML basic operation

xiaoxiao2021-03-06  105

1. XML Document Operation 1.1 Load an XML Document DIM Objdoc As New XmLDocument () - Load XML Document Sample.xml Objdoc.Load ("Sample.xml") 1.2 Load an XML Data Dim Objdoc As New XMLDocument () DIM Strxml As string strXml = " 12345 zhang bin '- load XML Data Objdoc. Load (strXml) 1.3 Save Document '-save XML Document Objdoc.save ("Sample.xml") 2 XML data query the most common XML data types are: Element, Attribute, Comment, Text. Element, Finger > Tom node. It can include: Element, Text, Comment, Processinginstruction, CData, And Entityreference, Attribute, refers to a bold portion in . Comment, finger, such as: . TEXT refers to the bold portion of Tom . In XML, you can use an XMLNode object to refer to a variety of XML data types. Both methods known absolute path above 2.1 query node (current) objNodeList = objDoc.SelectNodes ( "Company / Department / Employees / Employee") or objNodeList = objNode.SelectNodes ( "/ Company / Department / Employees / Employee") may Returns a NodeList object, if you want to return a single node, you can use the Selectsinglenode method, if you query one or more nodes, return the first node; if any node without query returning Nothing.

For example: objNode = objNode.selectsinglenode ("/ company / divartment / employees / employee) if not (objNode is nothing) THEN '- DO Process End If 2.2 Query Relative Path Node (Set) You can use the file path manner relative path to querying XML data objNode = objDoc.SelectSingleNode ( "Company / Department") objNodeList = objNode.SelectNodes ( "../ Department) objNode = objNode.SelectNode (" Employees / Employee ") 2.3 query known Nodes of the element name (set) When using an irregular hierarchy document, since it does not know the element name of the intermediate level, you can use the // symbol to cross the middle nodes, query all the other elements of the other elements, and many other elements. For example: objNodelist = objDoc.selectnodes 2.4 Element nodes (set), return properties, return properties, only need to adopt the corresponding method Pick up a @ symbol before the attribute name, for example: objNodelist = objdoc.selectnodes ("Company / Department / Employees / Employee / @ ID") ObjNodelist = Objdoc.selectNodes ("Company @ ID") 2.5 Query Text Node Use text () to get the Text node. ObjNode = ObjDoc.selectsinglenode ("Company / Department / Deparmt_name / text ()") 2.6 Querying the node of a particular condition using the [] symbol to query the node of a particular condition. For example: a. Return ID No. 10102 Employee Node ObjNode = Objdoc.selectsinglenode ("Company / Department / Employees / Employee [@ ID = '10102" ] ") B. Return Name to zhang qi Name Node ObjNode = Objdoc.selectsinglenode (" Company / Department / Employees / Employee / Name [Text () = 'zhang qi'] ") C. Return department contains staff 22345 Name Node ObjNode = Objdoc.selectsingLenode ("" Company / @ ID = '22345'] / divartment_name ") 2.7 Nodes for multi-mode Using | Symbols You can get multiple modes of multiple modes. For example: objNodeList = objdoc.selectnodes ("Company / Department / Department_name | Company / Department / Manager" 2.8 Querying Node Using * Symbols You can return all child nodes of the current node.

转载请注明原文地址:https://www.9cbs.com/read-100481.html

New Post(0)