Xml 查漏补缺笔记

    技术2022-05-11  60

    Special symbol: <FullName>Sylvie <Bellie> Aronson</FullName> The left/right angle brackets should be replaced with </> in xml node: <FullName>Sylvie <Bellie> Aronson</FullName>   XML & CSS: Xml: <? xml version = "1.0"?> <? xml:stylesheet href="StyleSheet1.css" type="text/css" ?> < Videos >             < Video >                         < Title > The Distinguished Gentleman</Title>                         < Director > Jonathan Lynn</Director>             </ Video > </ Videos > Css: Using the tag name (xml) for Element name (css) Title {             color: purple;             font-style: italic;             background-color: yellow; } Director {             background-color: #ff6666; }   Tag & Markup             A Markup means <tag> Root Node             An xml file must have one and only one root node; it could be accessed by the following 2 approaches: 1)     XmlDocument.DocumentElement 2)     XmlDocument.ChildNodes[0]   XmlNode & XmlElement             Node is more general than Element. Anything in an XML document is a node (e.g. attributes, comments, doctype, etc), but only tags are elements.             In .net, XmlElement and XmlAttribute are derived from XmlNode   Adding a new Element 1)     Approach 1: using TextNode NewElement = XmlDocument.CreateElement(“Tag”); NewText = XmlDocument.CreateTextNode(“content”); NewElement.AppendChild(NewText); ParentNode.AppendChild(NewElement);   2)     Approach 2: using InnerText NewElement = XmlDocument.CreateElement(“Tag”); NewElement.InnerText = “content”; ParentNode.AppendChild(NewElement);   3)     Approach 3: using InnerXml for nested nodes NewElement = XmlDocument.CreateElement(“Tag”); NewElement.InnerXml = “"<Title>Other People's Money</Title><Director>Alan Brunstein</Director><Length>114 Minutes</Length>"; ParentNode.AppendChild(NewElement);   Adding a new Attribute 1)     XmlNode.SetAttribute(“attributeName”, “attributeValue”);   2)     Document.CreateAttribute(), Attribute.SetValue, XmlNode.SetAttributeNode();   Attribute.OwnerElement             This property will return the XmlElement which owns this Attribute.             For XmlAttribute.ParentNode, it always returns null;   XmlComment <!--comments-->             It is also derived from XmlNode, and could be added by 2 steps:             XmlDocument.CreateComment(“comments”);             XmlElement.AppendChild(XmlComment);   Its text could be retrieved by InnerText or Value   CDATA <![CDATA[any text]]> Any text (include xml tags) inside the CDATA section will be considered to be regular text, the parser will not try to parse text inside the section. XmlCDataSection is also derived from XmlNode.             XmlDocument.CreateCDataSection(“some text<aa></bb”);             XmlElement.AppendChild(XmlCDataSection);   Its text could be retrieved by InnerText or Value   XmlNode.InnerText vs XmlNode.Value InnerText goes through the descendant XmlText node(s) of an XmlNode, and concatenates their value(s) together. Value just get the text of this node      

    最新回复(0)