zoukankan      html  css  js  c++  java
  • 读取含有命名空间xml文件内容

    .NET Language-Integrated Query for XML Data

    http://msdn.microsoft.com/library/bb308960.aspx 

    XNamespace myNs = "http://mycompany.com";
    
    XElement contacts =
       new XElement(myNs + "contacts",
          new XElement(myNs + "contact",
             new XElement(myNs + "name", "Patrick Hines"),
             new XElement(myNs + "phone", "206-555-0144", 
                 new XAttribute("type", "home")),
             new XElement(myNs + "phone", "425-555-0145",
                 new XAttribute("type", "work")),
             new XElement(myNs + "address",
                new XElement(myNs + "street1", "123 Main St"),
                new XElement(myNs + "city", "Mercer Island"),
                new XElement(myNs + "state", "WA"),
                new XElement(myNs + "postal", "68042")
             )
          )
       );

    产生如下文件:在最上层指定命名空间,分节点默认还有父节点的命名空间*继承性)

    <contacts xmlns="http://mycompany.com">
       <contact>
          <name>Patrick Hines</name>
          <phone type="home">206-555-0144</phone>
          <phone type="work">425-555-0145</phone>
          <address>
             <street1>123 Main St</street1>
             <city>Mercer Island</city>
             <state>WA</state>
             <postal>68042</postal>
          </address>
       </contact>
    </contacts>  

     XML Namespaces

    http://www.jclark.com/xml/xmlns.htm

    http://en.wikipedia.org/wiki/XML_namespace

    Code Project:

    http://www.codeproject.com/Articles/30965/Read-XML-with-Namespace-resolution-using-XLinq-XEl

    private Dictionary<KeyValuePair<string, string>, KeyValuePair<string, string>> RetriveDataFromXmLFile(string xmlFilePath, out KeyValuePair<string, string> guidComment, out KeyValuePair<string, string> guidDescription)
            {
                // XML format
                //<ConfigChangeGroup xmlns="urn:schemas.amc.com/Cdefce/Name/Mode/2011/04" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                //<Changes>
                //<ConfigChange>
                //<ConfigObjectType>EvaluationRule</ConfigObjectType> 
                //<ConfigVerb>Update</ConfigVerb> 
                //<Key>1055</Key> 
                //<NewConfig i:type="EvaluationRule">
                //<RuleId>1055</RuleId> 
                //<Name>AddPI_ACHCHECK_USs</Name> 
                //</NewConfig>
                //</ConfigChange>
                //</Changes>
                //<Comments>TestByBob3</Comments> 
                //<Description>TestByBob3</Description> 
                //<GroupId>86b6d584-2fb9-45fe-aea7-acc4479a3b3f</GroupId> 
                //</ConfigChangeGroup>
    
                Dictionary<KeyValuePair<string, string>, KeyValuePair<string, string>> groupsChange = new Dictionary<KeyValuePair<string, string>, KeyValuePair<string, string>>();
    
                XNamespace urnl = "urn:schemas.amc.com/Cdefce/Name/Mode/2011/04";
                XNamespace i = "http://www.w3.org/2001/XMLSchema instance";
    
                XElement elem = XElement.Load(xmlFilePath);
    
                string changeGuid = elem.Element(urnl + "GroupId").Value;
                string comments = elem.Element(urnl + "Comments").Value;
                string description = elem.Element(urnl + "Description").Value;
    
                guidComment = new KeyValuePair<string, string>(changeGuid, comments);
                guidDescription = new KeyValuePair<string, string>(changeGuid, description);
    
                var configChanges = elem.Elements(urnl + "Changes").Elements(urnl + "ConfigChange");
    
                foreach (var change in configChanges)
                {
                    string key = change.Element(urnl + "Key").Value;
                    string configObjectType = change.Element(urnl + "ConfigObjectType").Value;
                    string text = change.ToString();
    
                    KeyValuePair<string, string> idXml = new KeyValuePair<string, string>(changeGuid, text);
                    KeyValuePair<string, string> typeKey = new KeyValuePair<string, string>(configObjectType, key);
    
                    groupsChange.Add(typeKey, idXml);
                }
    
                return groupsChange;
            }
  • 相关阅读:
    Do You See Me? Ethical Considerations of the Homeless
    ELDER HOMELESSNESS WHY IS THIS AN ISSUE?
    Endoflife support is lacking for homeless people
    html内联框架
    html字体
    html块 div span
    html列表
    html表格
    SQL Server管理员专用连接的使用   作为一名DBA,经常会处理一些比较棘手的服务无响应问题,鉴于事态的严重性,多数DBA可能直接用“重启”大法,以便尽快的恢复生产环境的正常运转,但是多数情况
    如何配置最大工作线程数 (SQL Server Management Studio)
  • 原文地址:https://www.cnblogs.com/Jessy/p/2803595.html
Copyright © 2011-2022 走看看