English 中文(简体)
如何从Xml档案中获取某些内容?
原标题:How to get some content from xml file by powershell?

Variable $returnedxml is a sql query result forming in xml. I need to get content releasepath \sharespace est1\10.0.1212.00from it

<ReleasePath>\sharespace	est1\10.0.1212.00</ReleasePath>

我的守则如下:

 $xmldoc= new-object xml.xmldocument

 $xmldoc.load($Returnedxml)

 $xmldoc.releasepath

这里是返回的错误警报:

Exception calling "Load" with "1" argument(s): "Could not find file  C:UsersadminSystem.Xml.XmlDocument ."
At D:connecttods3andinvoke.ps1:47 char:14
+  $xmldoc.load <<<< ($Returnedxml)
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

我认为xml.xml文件是一种蚊帐,看来我错了。 因此,我可以做些什么?

问题回答

由于XML数据的处理对于如此众多的管理任务来说是不可或缺的,因此,Powerhell有一个XML型加速器。 因此,这也将发挥作用:

[xml]$xmldoc = $returnedxml
$xmldoc.releasepath

我刚刚把它读作一个示意图......

$file = [IO.File]::ReadAllText($filename)

然后利用Xpath从中获取价值......

$releasePath = $file | SelectXml "//ReleasePath"

XPath对于从XML档案中提取物品,比使用xmldoc更简单( wise智)来说,实在是强大的。

页: 1 但是,它目前是<代码>System.Xml.XmlDocument的物体。

So change your variable and then you can read the file.

或者,如果您在<条码>上已经有XmlDocument的标语的话。 页: 1 两者都属于同一类别。 公正使用费

You are using the wrong load; that one is for files. Use LoadXML instead:

$xmldoc.LoadXml($Returnedxml)




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签