Xml 查漏补缺笔记

 
Special symbol:
<FullName>Sylvie <Bellie> Aronson</FullName> 
The left/right angle brackets should be replaced with &lt;/&gt; in xml node:
<FullName>Sylvie &lt;Bellie&gt; 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
 
 
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值