There is a need:
To count all the configuration files, these profiles are in XML format and write them to the data table, and if there are comments to write these comments to the corresponding Configuration object Description field
<ItemID=""Key= "-1"FirstName=""Secondname=""Cssname= "hy"decription=""> </Item> <!--111 - <ItemID=""Key= "-1"FirstName=""Secondname=""Cssname=""decription= "" ></item>
As shown above, the 111 note is written to the following line record object up
The final object is: obj={id= "", Firstname= "", Secondname= "", descrition= "111"}
This function simple can no longer simple, on-line products are very many, various configuration files are also very many, some have comments, some no comments, how to ensure that these comments are added to the corresponding configuration record up?
The key point is how to judge the relationship between annotations and configuration objects:
There are two types of root nodes that are read to an XML file: comments and ELEMENT nodes, the logic is: each time the node is read to determine the node type, if the type is a comment, just clear the last node type, save this node type, if it is
element node type, just determine whether the last node type is a comment type if it is just added to the Description field, and then empty the previous node type, record this time the node type,
The process is as follows:
Code:
Only the previous node element type is saved in Flaglist, 0 represents the annotation type, and 1 indicates the element type:
varattributes =""; varKey =""; varTTTT = ( fromConfiginchXdoc.descendants ("Configuration"). Descendants ("appSettings") Selectconfig); foreach(varNodeinchtttt. Nodes ()) {if(node. NodeType = =System.Xml.XmlNodeType.Comment) {flaglist. Clear (); Attributes= node. ToString (). Replace ("<!--",""). Replace (" -",""); Flaglist. ADD (0); } if(node. NodeType = =System.Xml.XmlNodeType.Element) {if(Flaglist. Count = =1) { if(flaglist[0] ==1) {Attributes=""; }} flaglist. Clear (); Key= ((XElement) node). Attribute ("Key"). Value; Dic. ADD (key, attributes); Flaglist. ADD (1); } }
C # Read XML annotations