Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell&;LotusNotes—将While循环的输出从文本更改为XML输出_Xml_Powershell_View_While Loop_Lotus Notes - Fatal编程技术网

Powershell&;LotusNotes—将While循环的输出从文本更改为XML输出

Powershell&;LotusNotes—将While循环的输出从文本更改为XML输出,xml,powershell,view,while-loop,lotus-notes,Xml,Powershell,View,While Loop,Lotus Notes,我正在针对Lotus Notes服务器上的视图运行Powershell脚本。它目前以如下方式产生输出: UserID|Name|Internet Address user1|John Smith|john.smith@mycompany.com user2|Joe Smith|joe.smith@mycompany.com user3|Bill Smith|bill.smith@mycompany.com 注意:标题行当前不是输出的一部分,仅显示用于提供信息 输出当前转到文本文件,但我现在需要

我正在针对Lotus Notes服务器上的视图运行Powershell脚本。它目前以如下方式产生输出:

UserID|Name|Internet Address
user1|John Smith|john.smith@mycompany.com
user2|Joe Smith|joe.smith@mycompany.com
user3|Bill Smith|bill.smith@mycompany.com
注意:标题行当前不是输出的一部分,仅显示用于提供信息

输出当前转到文本文件,但我现在需要将其更改为XML格式。使用以下Powershell脚本提取数据

$session = New-Object -ComObject lotus.notessession
$session.initialize()
$session.notesversion

if (Test-Path -Path "c:\myfile.txt") {
    Remove-Item -Path "c:\myfile.txt" 
    }

$db = $session.GetDatabase("lotusServer","names.nsf")
$db.title

$view = $db.GetView('People')
Write-Host "View read : " $view.Name

# Show number of documents 
$nbrDocs = $view.AllEntries.Count 
Write-Host "Num of Docs : " $nbrDocs

# Get First Document in the View 
$doc = $view.GetFirstDocument()

#Read fields for current document 
$delim = "|" 
$i = 0 

    while ($doc -ne $null) {
        $internetAddress = [string] $doc.GetItemValue("InternetAddress") 
        $companyname = [string] $doc.GetItemValue("CompanyName") 
        $fullname = [string] $doc.GetItemValue("FullName")  
        if ( $companyname -eq "My Company") {
            $i = $i + 1
            # format the full name field
            $fullname = $fullname.Substring(3)
            $s = $fullname
            $c1 = $s.LastIndexOf(" ")
            $c2 = $s.IndexOf("/")
            $name = $s.Substring(0,$c2)
            $userID = $s.Substring($c1+1)

            $zOut = $userID + $delim + $name + $delim +  $internetAddress 
            Write-Host $zOut
            Write-Output $zOut| out-file "c:\myfile.txt" -append -width 2000
            } #end if
        $doc = $view.GetNextDocument($doc) 
    }  #end while
我希望现在的输出是类似于以下内容的XML格式:

<?xml version="1.0" ?> 
<Company>
   <UserID>user1
      <Name>John Smith</Name> 
      <InternetAddress>john.smith@mycompany.com</InternetAddress> 
   </UserID> 
</Company>

用户1
约翰·史密斯
厕所。smith@mycompany.com 
数据不应该有任何重复,并且(在某些情况下)输出中可能有多个公司,但总体而言,结构与上面的示例没有显著差异(Name和InternetAddress是UserID的子项)

然而,我现在解析数据的方式(虽然$doc-ne$null)一次只能看到一行。我发现的示例演示了如何导出/写入XML—一次执行,而不是一次执行一行。输出XML将在其他地方使用之前进行验证。我可以将此脚本的输出写入XML文件吗?如果可以,如何写入

如有任何想法/建议,不胜感激


谢谢

下一行处理记录输出

$zOut = $userID + $delim + $name + $delim +  $internetAddress 
您需要修改它,以便能够以XML的形式编写

例如:

$zOut = "<UserID>" + $userID + "</UserID>" ..... (etc)
$zOut=“”+$userID+”。。。。。(等)
一次只能看到一行,因为您在视图中遍历一组记录

如果希望一次获得所有数据,可以在查看URL查找中使用?ReadViewEntries&outputformat=XML设置。这样做是有限制的。详情如下:

或者,您可以在XPage中制作它,或者导出到DXL并通过XSLT进行转换


但这些替代方案将比你现在拥有的工作更多

谢谢,两位都很有帮助。我试过使用ReadViewEntries,但没有一个视图中只有这些字段。