BLOG ARTICLE DEVELOP/XML | 3 ARTICLE FOUND

  1. 2008.12.14 오피스 문서 처리
  2. 2008.08.14 코딩을 통한 다중 네임스페이스를 지닌 XML 개체 작성법 3
  3. 2006.11.20 XML 교육 진행 순서

오피스 문서 처리

DEVELOP/XML 2008. 12. 14. 21:58

지난 금요일 VSUG의 첫번째 주제였던 VSTO 3.0에 관한 내용을 적어둔다.(까먹지말라고)

오피스 2007과 VS2008을 이어주는 녀석이 VSTO 3.0이다.

좀더 원활히 다루기위해 Open Xml Format SDK 1.0(2.0은 현재 CTP판)과 CodeSnippet

도 설치하자.

.netFramework 3.0이후로 오면서 좋아진점이.. Zip을 안까고 접근이 가능해졌다.
System.IO.Packaging 을 이용한것인데, 많이 편하다 (파일및 디렉토리 제어권이 안풀려서 예외 날아오지도 않고..)^^

        private void doWork(string fileName)
        {
            WordprocessingDocument doc = WordprocessingDocument.Open(fileName,true);

            MainDocumentPart mdp = doc.MainDocumentPart;
            WordprocessingCommentsPart cmtPart = mdp.WordprocessingCommentsPart;

            XmlDocument docXml = new XmlDocument();
            docXml.Load(mdp.GetStream());
            
            XmlNodeList xnl = docXml.GetElementsByTagName(@"w:t");
            
            int i = 0;
            
            foreach (XmlNode node in xnl)
            {
                node.InnerText = "text" + i;
                i++;
            }

            docXml.Save(mdp.GetStream(FileMode.Create,FileAccess.Write));
            doc.Close();
        }

다음에 갈아엎을때 도입하고 싶네.. ^^

추가 : http://msdn.microsoft.com/ko-kr/magazine/cc164242.aspx 

AND

종종보면 다중네임스페이스를 지닌 xml개체를 보게되는데
가지고 있는 책에는 예제가 없어 구글링 하다 알게된 자료..

두가지방법중 난 후자를 선택해서 코딩했다..

Samples are bellow.

As you can see populating XmlDocument with XmlWriter.Write*() methods is much simpler.

string myNS = "http://www.xyz.space.com/land";

// Populating XmlDocument using DOM API:
XmlDocument xdoc1 = new XmlDocument();
XmlElement rootABC = xdoc1.CreateElement("rootABC", myNS);
xdoc1.AppendChild(rootABC);
XmlElement ele1 = xdoc1.CreateElement("ele1", myNS);
rootABC.AppendChild(ele1);
XmlAttribute xsd = xdoc1.CreateAttribute("xmlns", "xsd", "http://www.w3.org/2000/xmlns/");
xsd.Value = "http://www.xyz.space.com/Airschemas";
ele1.Attributes.Append(xsd);
XmlAttribute xsi = xdoc1.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/");
xsi.Value = "http://www.xyz.space.com/AirschemaInst";
ele1.Attributes.Append(xsi);
XmlElement ObjVal = xdoc1.CreateElement("ObjVal", myNS);
ele1.AppendChild(ObjVal);
XmlElement Name = xdoc1.CreateElement("Name", myNS);
ObjVal.AppendChild(Name);
Name.AppendChild(xdoc1.CreateTextNode("POC2"));

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter w1 = XmlWriter.Create(Console.Out, settings);

xdoc1.WriteTo(w1);
Console.WriteLine();
Console.WriteLine();

// Populating XmlDocument using XPathNavigator API:
XmlDocument xdoc2 = new XmlDocument();
XmlWriter docWriter = xdoc2.CreateNavigator().AppendChild();
docWriter.WriteStartElement("rootABC", myNS);
docWriter.WriteStartElement("ele1", myNS);
docWriter.WriteAttributeString("xmlns", "xsd", "http://www.w3.org/2000/xmlns/", "http://www.xyz.space.com/Airschemas");
docWriter.WriteAttributeString("xmlns", "xsi", "http://www.w3.org/2000/xmlns/", "http://www.xyz.space.com/AirschemaInst");
docWriter.WriteStartElement("ObjVal", myNS);
docWriter.WriteElementString("Name", myNS, "POC2");

docWriter.WriteEndElement();
docWriter.WriteEndElement();
docWriter.WriteEndElement();
docWriter.Close();

XmlWriter w2 = XmlWriter.Create(Console.Out, settings);
xdoc2.WriteTo(w2);
Console.WriteLine();
Console.WriteLine();
w2.Flush();




WebData/Sergey

출처 : http://www.bokebb.com/dev/english/1932/posts/19324822.shtml
AND

XML기초
1장XML소개

2장
XML학습준비

3장
DTD(X)

4장
Namespace

5장
XML Schema

6장
XPath

7장
XSL
C#+XML
8장
XML문서읽기

9장
XML문서작성

10장
DOM

11장
XSLT

12장

AND