标签: xmldocument

如何将xml节点作为第一个子节点插入到java中的另一个xml文档中?

例如.根=

<root>
  <param value="abc">
  <param value="bc">
</root>
Run Code Online (Sandbox Code Playgroud)

NodeToInsert可以是

<insert><parameterDesc>afds</parameterDesc></insert>
Run Code Online (Sandbox Code Playgroud)

输出应该是:

<root>
  <insert><parameterDesc>afds</parameterDesc></insert>
  <param value="abc">
  <param value="bc">
</root>  
Run Code Online (Sandbox Code Playgroud)

java xml xmldocument

3
推荐指数
1
解决办法
6674
查看次数

XmlDocument并使用xPath获取特定属性

我在这里看到了几个例子,其中Xpath与XmlDocument一起使用,以从XmlDocument节点获取特定属性....

Console.WriteLine(xmlDocument.SelectSingleNode("//dataTemplateSpecification/templates/template/elements/element/@name").Value.ToString());
Run Code Online (Sandbox Code Playgroud)

出于某种原因,我得到一个"对象引用未设置为对象的实例".例外.每当我遇到特定的代码行时.我有一个小测试应用程序,我已经设置为测试不同的东西,然后我把它们放入我的主项目...

这是代码......

namespace ReadXml
{
    class Program
    {
        static void Main(string[] args)
        {
            //string fulXmlPath =     System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/templateExample.xml");
            XDocument xDocument = XDocument.Load("C:\\Users\\derekww\\Documents\\XML Documents\\templateExample.xml");
            XElement elem = xDocument.Element("dataTemplateSpecification"); ;
            XmlDocument xmlDocument = new XmlDocument();
            StreamReader file = new StreamReader("C:\\Users\\derekww\\Documents\\XML Documents\\templateExample.xml");

            xmlDocument.Load(file);

            //XmlDocument theDoc = new XmlDocument();
            //using (var xmlReader = xDocument.CreateReader())
            //{
            //    xmlDocument.Load(xmlReader);
            //}

            //Console.WriteLine(elem.ToString());
            XmlNode xNode = xmlDocument.SelectSingleNode("//dataTemplateSpecification/templates/template/elements/element");
            Console.WriteLine("WORK PLEASE!!!! {0}", xNode.Value.ToString());
            //Console.WriteLine(xmlDocument.SelectSingleNode("//dataTemplateSpecification/templates/template/elements/element/@name").Value.ToString());
            //Console.WriteLine("This better Work>>>> {0}", xmlDocument.Attributes["/dataTemplateSpecification/templates/template/elements/element/@name"].Value);
            Console.ReadLine();
            //Console.WriteLine("This better Work>>>> {0}", xmlDocument.SelectSingleNode("//dataTemplateSpecification/templates/template/elements/element/@name").Value);
            //foreach (String AttVal in …
Run Code Online (Sandbox Code Playgroud)

c# xml xpath xmldocument xml-attribute

3
推荐指数
1
解决办法
8906
查看次数

HTML文档

是否有工具从VS2010生成的XML文档文件生成HTML页面?

我搜索谷歌这样的工具,但找不到一个.

我下载并安装了SandCastle,但我无法理解如何使用它.

c# xmldocument visual-studio-2010

3
推荐指数
1
解决办法
155
查看次数

使用C#在内存中进行XSLT转换

大家下午好,

我不知道为什么这证明是如此困难,但我必须有其中一天!

我试图在内存中执行XslCompiledTransform XmlDocument(我已从Web服务检索XML并保存到数据库中)对象.到目前为止,我有以下代码:

        string xslFile = "C:\\MOJLogViewer\\GetClaimTransformed.xslt";

        XslCompiledTransform processor = new XslCompiledTransform();
        processor.Load(xslFile);

        MemoryStream ms = new MemoryStream();
        processor.Transform(xdoc.CreateNavigator(), null, ms);

        ms.Seek(0, SeekOrigin.Begin);

        StreamReader reader = new StreamReader(ms);

        XmlDocument transformedDoc = new XmlDocument();
        transformedDoc.Load(reader.ReadToEnd());


        string output = reader.ReadToEnd();
        ms.Close();
Run Code Online (Sandbox Code Playgroud)

当我尝试运行此代码时,我得到"路径中的非法字符"异常.该路径不包含任何非法字符,所以我绝对难倒!

我希望你能提供帮助.

谢谢

.net c# xml xslt xmldocument

3
推荐指数
1
解决办法
6873
查看次数

如何在C#中使用XML前缀?

编辑:我现在发布了我的应用程序:http://pastebin.com/PYAxaTHU

我试图制作基于控制台的应用程序来恢复我的温度.

using System;
using System.Xml;


namespace GetTemp
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(downloadWebPage(
             "http://www.andrewmock.com/uploads/example.xml"
            ));

            XmlNamespaceManager man = new XmlNamespaceManager(doc.NameTable);
            man.AddNamespace("aws", "www.aws.com/aws");

            XmlNode weather = doc.SelectSingleNode("aws:weather", man);
            Console.WriteLine(weather.InnerText);
            Console.ReadKey(false);
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

以下是XML示例:

<aws:weather xmlns:aws="http://www.aws.com/aws">
   <aws:api version="2.0"/>
   <aws:WebURL>http://weather.weatherbug.com/WA/Kenmore-weather.html?ZCode=Z5546&Units=0&stat=BOTHL</aws:WebURL>
   <aws:InputLocationURL>http://weather.weatherbug.com/WA/Kenmore-weather.html?ZCode=Z5546&Units=0</aws:InputLocationURL>
   <aws:station requestedID="BOTHL" id="BOTHL" name="Moorlands ES" city="Kenmore" state=" WA" zipcode="98028" country="USA" latitude="47.7383346557617" longitude="-122.230278015137"/>
   <aws:current-condition icon="http://deskwx.weatherbug.com/images/Forecast/icons/cond024.gif">Mostly Cloudy</aws:current-condition>
   <aws:temp units="&deg;F">40.2</aws:temp>
   <aws:rain-today units=""">0</aws:rain-today>
   <aws:wind-speed units="mph">0</aws:wind-speed>
   <aws:wind-direction>WNW</aws:wind-direction>
   <aws:gust-speed units="mph">5</aws:gust-speed>
   <aws:gust-direction>NW</aws:gust-direction>
</aws:weather>
Run Code Online (Sandbox Code Playgroud)

我只是不确定如何在这里正确使用XML前缀.这有什么问题?

.net c# xml xmldocument

3
推荐指数
1
解决办法
1477
查看次数

.NET XMLDocument 编码问题

我目前正面临一个非常具体的问题。我将一些数据存储在 XMLDocument 中并将其保存在 HDD 上。他们看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<Settings>
  <Units>
    <Unit>
      <Name>Kilogramm</Name>
      <ShortName>Kg</ShortName>
    </Unit>
    <Unit>
      <Name>Flasche(n)</Name>
      <ShortName>Fl</ShortName>
    </Unit>
    <Unit>
      <Name>Stück</Name>
      <ShortName>St</ShortName>
    </Unit>
    <Unit>
      <Name>Beutel</Name>
      <ShortName>Btl</ShortName>
    </Unit>
    <Unit>
      <Name>Schale</Name>
      <ShortName>Sch</ShortName>
    </Unit>
    <Unit>
      <Name>Kiste</Name>
      <ShortName>Ki</ShortName>
    </Unit>
    <Unit>
      <Name>Meter</Name>
      <ShortName>m</ShortName>
    </Unit>
    <Unit>
      <Name>Stunde(n)</Name>
      <ShortName>h</ShortName>
    </Unit>
    <Unit>
      <Name>Glas</Name>
      <ShortName>Gl</ShortName>
    </Unit>
    <Unit>
      <Name>Portion</Name>
      <ShortName>Port</ShortName>
    </Unit>
    <Unit>
      <Name>Dose</Name>
      <ShortName>Do</ShortName>
    </Unit>
    <Unit>
      <Name>Paket</Name>
      <ShortName>Pa</ShortName>
    </Unit>
  </Units>
</Settings>
Run Code Online (Sandbox Code Playgroud)

我正在通过 XMLDocument.Load() 加载文件并使用 XMLDocument.Save() 保存它。但是现在我从旧 PC 中保存了文件,现在在保存和重新加载后,特殊字符 (ä,ö,ü) 出现异常。
事实上,在记事本中查看文件没有任何区别,但在十六进制上查看有一些!这怎么可能?

.net c# vb.net xmldocument

3
推荐指数
1
解决办法
9915
查看次数

如何从CDATA中删除href标记

我在xml文档中有以下CDATA:

<![CDATA[ <p xmlns="">Refer to the below: <br/>
</p>
<table xmlns:abc="http://google.com pic.xsd" cellspacing="1" class="c" type="custom" width="100%">
    <tbody>
        <tr xmlns="">            
            <th style="text-align: left">Basic offers...</th>
        </tr>
        <tr xmlns="">
            <td style="text-align: left">Faster network</td>
            <td style="text-align: left">
            <ul>                
                <li>Session</li>
            </ul>
            </td>
        </tr>
        <tr xmlns="">
            <td style="text-align: left">capabilities</td>
            <td style="text-align: left">
            <ul>                
                <li>Navigation,</li>
                <li>message, and</li>
                <li>contacts</li>
            </ul>
            </td>
        </tr>
        <tr xmlns="">
            <td style="text-align: left">Data</td>
            <td style="text-align: left">
            <p>Here visit google for more info <a href="http://www.google.com" target="_blank"><font color="#0033cc">www.google.com</font></a>.</p>
            <p>Remove this href tag <a href="/abc/def/{T}/t/1" target="_blank">Information</a> remove …
Run Code Online (Sandbox Code Playgroud)

c# xml xmldocument

3
推荐指数
1
解决办法
1788
查看次数

如何使用 XMLDocument 类从 C# 中的 XML 文件中获取数据?

大家晚上好,周末快乐!。

我一整天都在尝试了解如何解析我的简单 XML 文件,以便我能够充分理解它来编写我想要从事的个人项目。

我一直在阅读本网站和其他网站上的文章,但无法超越我所在的位置:(

我的 XML 文档是...

<XML>
  <User>
    <ID>123456789</ID>
    <Device>My PC</Device>
  </User>
  <History>
    <CreationTime>27 June 2013</CreationTime>
    <UpdatedTime>29 June 2013</UpdatedTime>
    <LastUsage>30 June 2013</LastUsage>
    <UsageCount>103</UsageCount>
  </History>
  <Configuration>
    <Name>Test Item</Name>
    <Details>READ ME</Details>
    <Enabled>true</Enabled>   
  </Configuration>
</XML>
Run Code Online (Sandbox Code Playgroud)

我正在尝试获取详细信息元素中的值(自述)。下面是我的代码

// Start Logging Progress
Console.WriteLine("Test Application - XML Parsing and Creating");
Console.ReadKey();

// Load XML Document
XmlDocument MyDoc = new XmlDocument();  MyDoc.Load(@"E:\MyXML.XML");

// Select Node
XmlNode MyNode = MyDoc.SelectSingleNode("XML/Configuration/Details");

// Output Node Value
Console.WriteLine(String.Concat("Details: ", MyNode.Value));

// Pause
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)

我的控制台应用程序正在运行并输出“目标:”,但没有提供元素中的详细信息。

有人能明白为什么会这样吗,如果我完全不在状态,也许会给我建议?我以前没有阅读 XML 文件的知识;因此我现在在哪里:)

谢谢!汤姆

c# xml xmldocument

3
推荐指数
1
解决办法
3万
查看次数

如何在 C# 中向 XmlDocument() 的根节点添加属性

我已经在 C# 中有一个 XmlDocument 对象。假设 InnerXml 看起来像这样;

<MyResponse>
  <ResponseType>
    <Id>8825</Id>
  </ResponseType>
</MyResponse>
Run Code Online (Sandbox Code Playgroud)

如何添加名称为 uuid 且值为 781283721381 的属性,例如 uuid="781283721381"。所以我的 Xml 输出如下所示;

<MyResponse uuid="781283721381">
  <ResponseType>
    <Id>8825</Id>
  </ResponseType>
</MyResponse>
Run Code Online (Sandbox Code Playgroud)

c# xmldocument xml-attribute document-root

3
推荐指数
1
解决办法
3009
查看次数

将兄弟节点插入xml文档

我有一个.net Web应用程序,它使用XmlDocument加载XML String.XML的格式如下:

<Sections name="Section Opening Page" PageContentID="201" Template="ReportTags">
  <Chapter Name="Introduction" PageContentID="202" Template="ReportTags">
    <Pages Name="Why this Document?" PageContentID="203" Template="ReportTags" />
    <Pages Name="Target Audience" PageContentID="204" Template="ReportTags" />
  </Chapter>
  <Chapter Name="Detailed Results" PageContentID="205" Template="ReportTags">
    <Pages Name="Question List" PageContentID="206" Template="ReportTags" />
    <Pages Name="Answers" PageContentID="207" Template="ReportTags" />
    <Pages Name="Comments" PageContentID="208" Template="ReportTags" />
  </Chapter>
  <Chapter Name="Appendix 1" PageContentID="209" Template="ReportTags">
    <Pages Name="Page 1" PageContentID="210" Template="ReportTags" />
    <Pages Name="Page 2" PageContentID="211" Template="ReportTags" />
    <Pages Name="Page 3" PageContentID="212" Template="ReportTags" />
  </Chapter>
  <Chapter Name="Appendix 2" PageContentID="213" Template="ReportTags">
    <Pages Name="Page …
Run Code Online (Sandbox Code Playgroud)

.net c# xml xpath xmldocument

3
推荐指数
1
解决办法
3979
查看次数