Xml원본
<?xml version="1.0" encoding="utf-8" ?>
<basket>
<item>
<scene rc="0 0 590 420" embedCount="9">
<image rc="0 0 590 420" priority="0" />
</scene>
</item>
</basket>
<basket>
<item>
<scene rc="0 0 590 420" embedCount="9">
<image rc="0 0 590 420" priority="0" />
</scene>
</item>
</basket>
1. 속성삭제
- image노드의 rc속성을 삭제해보자
XmlDocument doc = new XmlDocument();
doc.Load("xml경로");
XmlNode node = doc.SelectSingleNode("/descendant::basket/item/scene/image");
XmlAttributeCollection acxNode = node.Attributes;
if(acxNode.GetNamedItem("rc") != null)
{
acxNode.Remove((XmlAttribute)acxNode.GetNamedItem("rc"))
}
doc.Save("경로");
doc.Load("xml경로");
XmlNode node = doc.SelectSingleNode("/descendant::basket/item/scene/image");
XmlAttributeCollection acxNode = node.Attributes;
if(acxNode.GetNamedItem("rc") != null)
{
acxNode.Remove((XmlAttribute)acxNode.GetNamedItem("rc"))
}
doc.Save("경로");
2. 속성값 수정
- image노드의 rc속성값을 변경해보자
XmlDocument doc = new XmlDocument();
doc.Load("xml경로");
XmlNode node = doc.SelectSingleNode("/descendant::basket/item/scene/image");
XmlAttributeCollection acxNode = node.Attributes;
if(acxNode.GetNamedItem("rc") != null)
{
acxNode.GetNamedItem("rc").Value = "0 0";
}
doc.Save("경로");
doc.Load("xml경로");
XmlNode node = doc.SelectSingleNode("/descendant::basket/item/scene/image");
XmlAttributeCollection acxNode = node.Attributes;
if(acxNode.GetNamedItem("rc") != null)
{
acxNode.GetNamedItem("rc").Value = "0 0";
}
doc.Save("경로");
3. 속성값 추가
- image노드에 test노드를 추가해보자
XmlDocument doc = new XmlDocument();
doc.Load("xml경로");
XmlNode node = doc.SelectSingleNode("/descendant::basket/item/scene/image");
XmlAttributeCollection acxNode = node.Attributes;
XmlAttribute newAttr = doc.CreateAttribute("test");
newAttr.Value = "속성값";
acxNode.SetNamedItem(newAttr);
doc.Save("경로");
doc.Load("xml경로");
XmlNode node = doc.SelectSingleNode("/descendant::basket/item/scene/image");
XmlAttributeCollection acxNode = node.Attributes;
XmlAttribute newAttr = doc.CreateAttribute("test");
newAttr.Value = "속성값";
acxNode.SetNamedItem(newAttr);
doc.Save("경로");
'.net' 카테고리의 다른 글
Ping Class (2) | 2009.01.23 |
---|---|
Image Resizing (0) | 2008.12.23 |
Xml 수정하기(update) (0) | 2008.07.08 |