Hello
I have an Infopath Doc that is stored as XML on our SP farm, I am trying to access certain information in the infopath form to assign as a variable for use in creating folder structures and websites. That is not too hard when dealing with clearly named elements in the xml doc, however on large deployments it is possible to have 4 servers or more on the proxy layer and the same on the app layer as well as multiple URLS. I am looking for a way to parse thruough the XML and:1) Identify the number of layers per environment ie.. ProxyLayer[0], ProxyLayer[1], ProxyLayer[2] so on and so forth
2) Within each of these are items I would like to access and automatically assign to variables.
I am not sure how to parse the XML and identify how many proxy layers there would be and then once I do how do I extract and assign each item on a per layer basis.
Here is a section of the proxy layer
<my:ProxyLayer><my:ExistingURL>false</my:ExistingURL><my:NewURL>true</my:NewURL><my:URL>int.esig.url.com</my:URL><my:GSS></my:GSS><my:CSS></my:CSS><my:ACE>ACE</my:ACE><my:DNS>DNS</my:DNS><my:SSL>SSL</my:SSL><my:ServerTable><my:HostName>HOSTNAME</my:HostName><my:IPAddress>IPAddress</my:IPAddress><my:PortNumber>11023</my:PortNumber><my:Location>location</my:Location></my:ServerTable><my:ServerTable xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-05-12T18:19:05"><my:HostName>HOST</my:HostName><my:IPAddress></my:IPAddress><my:PortNumber>11023</my:PortNumber><my:Location> DMZ</my:Location></my:ServerTable><my:ACEConfig><my:Config>ACE Configuration</my:Config><my:SSLReq>1</my:SSLReq><my:Encrypt>2</my:Encrypt><my:KeepAliveLocation></my:KeepAliveLocation><my:KeepaliveType>1</my:KeepaliveType><my:SameNetworkSeg>1</my:SameNetworkSeg><my:InternalVIP>1</my:InternalVIP><my:externalVIP></my:externalVIP><my:ExternalFirewallGroup><my:firewallRequest></my:firewallRequest></my:ExternalFirewallGroup><my:Redirect>1</my:Redirect><my:RedirectGroup><my:Port1>11023</my:Port1><my:URLNonSSL>int.esig.url.com</my:URLNonSSL><my:Port2>11023</my:Port2></my:RedirectGroup><my:RedirectGroupSSL><my:SSLPort1>11023</my:SSLPort1><my:SSLUrl>int.esig.url.com</my:SSLUrl><my:SSLPort2>11023</my:SSLPort2></my:RedirectGroupSSL><my:StickyType>2</my:StickyType><my:SiteURLs>2</my:SiteURLs><my:NotNeeded>Not Needed</my:NotNeeded><my:All>All</my:All></my:ACEConfig><my:DNSGroup><my:METNET>true</my:METNET><my:MET_INTNET>true</my:MET_INTNET><my:EXTERNAL>false</my:EXTERNAL></my:DNSGroup><my:GSSGroup><my:Balance></my:Balance><my:FailoverGroup><my:PrimarySite></my:PrimarySite><my:SecondarySite></my:SecondarySite></my:FailoverGroup><my:SorryServer></my:SorryServer><my:KeepaliveGss></my:KeepaliveGss><my:DNSLocal></my:DNSLocal><my:ExtFirewall></my:ExtFirewall><my:ExtNAT></my:ExtNAT><my:InterGSS>false</my:InterGSS><my:ExtGSS>false</my:ExtGSS></my:GSSGroup></my:ProxyLayer>
Without knowing your complete document, it is a bit hard to answer the question. You could use XPath though to find all nodes of a given type like this:
$xml.SelectNodes("//item")
And this would give you the number:
@($xml.SelectNodes("//item")).Count
or
$xml.SelectNodes("//item") | Measure-Object
Hi Tobias, Thank you for the quick response, and I am sorry for not giving enough information. Here is the complete XML doc, you will notice there are 2 sections called Proxy Layer, each layer is associated with a different URL.
I am new to PS and I have never dealt with XML but this is alot of fun
Thank you
Robert Burke
<?xml version="1.0" encoding="utf-8"?><?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:Network-Request:-myXSD-2010-05-12T18-19-05" solutionVersion="1.0.0.304" PIVersion="1.0.0.0" href="http://connect.URL.com/itg/EI/TS_WinAppEng/NetworkRequest/Forms/template.xsn" productVersion="12.0.0.0"?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?><my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-05-12T18:19:05" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-US"> <my:CurrentUser>rburke4</my:CurrentUser> <my:ContactName>Robert Burke</my:ContactName> <my:ContactPhone>555-1212</my:ContactPhone> <my:AppName></my:AppName> <my:LOB>A&H</my:LOB> <my:Environment>Integration</my:Environment> <my:EAICode>8022</my:EAICode> <my:AISEnvironment></my:AISEnvironment> <my:RemedyTicket></my:RemedyTicket> <my:EngNotes><html xmlns="http://www.w3.org/1999/xhtml" xml:space="preserve"><div>Please use cookie as the sticky type for both URLS, this will be a test for the network team. This form will not let me select cookie for both due to past issues</div></html></my:EngNotes> <my:AppLayer> <my:AppURL>app.int.esig.URL.com</my:AppURL> <my:AppGSS></my:AppGSS> <my:AppCSS></my:AppCSS> <my:AppACE>ACE</my:AppACE> <my:AppDNS>DNS</my:AppDNS> <my:AppSSL>SSL</my:AppSSL> <my:AppExisting>false</my:AppExisting> <my:AppNewURL>true</my:AppNewURL> <my:AppServerTable> <my:AppHostName>SERVERNAME</my:AppHostName> <my:AppIP>IP ADDRESS</my:AppIP> <my:AppPort>11023</my:AppPort> <my:AppLocation>SISC BASTION</my:AppLocation> </my:AppServerTable> <my:AppAceGroup> <my:appKeepAliveLocation>ACE Configuration</my:appKeepAliveLocation> <my:AppSSLReq>1</my:AppSSLReq> <my:AppEncryption>2</my:AppEncryption> <my:AppKeepaliveType>3</my:AppKeepaliveType> <my:AppKeepaliveLocation>/public/keepalive/keepalive.aspx</my:AppKeepaliveLocation> <my:AppStickyType>1</my:AppStickyType> <my:AppSiteSpecific>2</my:AppSiteSpecific> <my:AppFirewallGroup> <my:AppExternalFirewallRequest></my:AppExternalFirewallRequest> </my:AppFirewallGroup> <my:AppRedirectGroup> <my:AppPort1>11023</my:AppPort1> <my:AppURLNonSSL>app.int.esig.URL.com</my:AppURLNonSSL> <my:AppPort2>11023</my:AppPort2> </my:AppRedirectGroup> <my:AppRedirectGroupSSL> <my:AppSSLPort1>11023</my:AppSSLPort1> <my:AppSSLURL>app.int.esig.URL.com</my:AppSSLURL> <my:AppSSLPort2>11023</my:AppSSLPort2> </my:AppRedirectGroupSSL> <my:AppSameNetworkSeg>1</my:AppSameNetworkSeg> <my:AppInternalVIP>1</my:AppInternalVIP> <my:AppExternalVIP>2</my:AppExternalVIP> <my:AppRedirect>1</my:AppRedirect> <my:AppNotNeeded>Not Needed</my:AppNotNeeded> </my:AppAceGroup> <my:AppDNSGroup> <my:AppMetnet>true</my:AppMetnet> <my:AppMetintnet>true</my:AppMetintnet> <my:AppExternal>false</my:AppExternal> </my:AppDNSGroup> <my:AppGSSGroup> <my:AppInternalGSS>false</my:AppInternalGSS> <my:AppExternalGSS>false</my:AppExternalGSS> <my:AppFailoverGroup> <my:AppPrimarySite></my:AppPrimarySite> <my:AppSecondarySite></my:AppSecondarySite> </my:AppFailoverGroup> <my:AppBalance></my:AppBalance> <my:AppSorryServer></my:AppSorryServer> <my:AppKeepAliveGSS></my:AppKeepAliveGSS> <my:AppDNSLocal></my:AppDNSLocal> <my:AppExtFirewall></my:AppExtFirewall> <my:AppExtNAT></my:AppExtNAT> </my:AppGSSGroup> </my:AppLayer> <my:ProxyLayer> <my:ExistingURL>false</my:ExistingURL> <my:NewURL>true</my:NewURL> <my:URL>int.esig.URL.com</my:URL> <my:GSS></my:GSS> <my:CSS></my:CSS> <my:ACE>ACE</my:ACE> <my:DNS>DNS</my:DNS> <my:SSL>SSL</my:SSL> <my:ServerTable> <my:HostName>SERVERNAME</my:HostName> <my:IPAddress>IP ADDRESS</my:IPAddress> <my:PortNumber>11023</my:PortNumber> <my:Location>SISC DMZ</my:Location> </my:ServerTable><my:ServerTable xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-05-12T18:19:05"><my:HostName>METINTSV207</my:HostName><my:IPAddress>172.24.49.13</my:IPAddress><my:PortNumber>11023</my:PortNumber><my:Location>SISC DMZ</my:Location></my:ServerTable> <my:ACEConfig> <my:Config>ACE Configuration</my:Config> <my:SSLReq>1</my:SSLReq> <my:Encrypt>2</my:Encrypt> <my:KeepAliveLocation></my:KeepAliveLocation> <my:KeepaliveType>1</my:KeepaliveType> <my:SameNetworkSeg>1</my:SameNetworkSeg> <my:InternalVIP>1</my:InternalVIP> <my:externalVIP></my:externalVIP> <my:ExternalFirewallGroup> <my:firewallRequest></my:firewallRequest> </my:ExternalFirewallGroup> <my:Redirect>1</my:Redirect> <my:RedirectGroup> <my:Port1>11023</my:Port1> <my:URLNonSSL>int.esig.URL.com</my:URLNonSSL> <my:Port2>11023</my:Port2> </my:RedirectGroup> <my:RedirectGroupSSL> <my:SSLPort1>11023</my:SSLPort1> <my:SSLUrl>int.esig.URL.com</my:SSLUrl> <my:SSLPort2>11023</my:SSLPort2> </my:RedirectGroupSSL> <my:StickyType>2</my:StickyType> <my:SiteURLs>2</my:SiteURLs> <my:NotNeeded>Not Needed</my:NotNeeded> <my:All>All</my:All> </my:ACEConfig> <my:DNSGroup> <my:METNET>true</my:METNET> <my:MET_INTNET>true</my:MET_INTNET> <my:EXTERNAL>false</my:EXTERNAL> </my:DNSGroup> <my:GSSGroup> <my:Balance></my:Balance> <my:FailoverGroup> <my:PrimarySite></my:PrimarySite> <my:SecondarySite></my:SecondarySite> </my:FailoverGroup> <my:SorryServer></my:SorryServer> <my:KeepaliveGss></my:KeepaliveGss> <my:DNSLocal></my:DNSLocal> <my:ExtFirewall></my:ExtFirewall> <my:ExtNAT></my:ExtNAT> <my:InterGSS>false</my:InterGSS> <my:ExtGSS>false</my:ExtGSS> </my:GSSGroup> </my:ProxyLayer> <my:ProxyLayer> <my:ExistingURL>false</my:ExistingURL> <my:NewURL>true</my:NewURL> <my:URL>int.services.esig.URL.com</my:URL> <my:GSS></my:GSS> <my:CSS></my:CSS> <my:ACE>ACE</my:ACE> <my:DNS>DNS</my:DNS> <my:SSL>SSL</my:SSL> <my:ServerTable> <my:HostName>SERVERNAME</my:HostName> <my:IPAddress>IP ADDRESS</my:IPAddress> <my:PortNumber>11024</my:PortNumber> <my:Location>RISC DMZ</my:Location> </my:ServerTable> <my:ServerTable> <my:HostName>SERVERNAME</my:HostName> <my:IPAddress>IP ADDRESS</my:IPAddress> <my:PortNumber>11024</my:PortNumber> <my:Location>RISC DMZ</my:Location> </my:ServerTable><my:ACEConfig> <my:Config>ACE Configuration</my:Config> <my:SSLReq>1</my:SSLReq> <my:Encrypt>2</my:Encrypt> <my:KeepAliveLocation></my:KeepAliveLocation> <my:KeepaliveType>1</my:KeepaliveType> <my:SameNetworkSeg>1</my:SameNetworkSeg> <my:InternalVIP>1</my:InternalVIP> <my:externalVIP>2</my:externalVIP> <my:ExternalFirewallGroup> <my:firewallRequest></my:firewallRequest> </my:ExternalFirewallGroup> <my:Redirect>1</my:Redirect> <my:RedirectGroup> <my:Port1>11024</my:Port1> <my:URLNonSSL>int.services.esig.URL.com</my:URLNonSSL> <my:Port2>11024</my:Port2> </my:RedirectGroup> <my:RedirectGroupSSL> <my:SSLPort1>11024</my:SSLPort1> <my:SSLUrl>int.services.esig.URL.com</my:SSLUrl> <my:SSLPort2>11024</my:SSLPort2> </my:RedirectGroupSSL> <my:StickyType>2</my:StickyType> <my:SiteURLs>2</my:SiteURLs> <my:NotNeeded>Not Needed</my:NotNeeded> <my:All>All</my:All> </my:ACEConfig> <my:DNSGroup> <my:METNET>true</my:METNET> <my:MET_INTNET>true</my:MET_INTNET> <my:EXTERNAL>false</my:EXTERNAL> </my:DNSGroup> <my:GSSGroup> <my:Balance></my:Balance> <my:FailoverGroup> <my:PrimarySite></my:PrimarySite> <my:SecondarySite></my:SecondarySite> </my:FailoverGroup> <my:SorryServer></my:SorryServer> <my:KeepaliveGss></my:KeepaliveGss> <my:DNSLocal></my:DNSLocal> <my:ExtFirewall></my:ExtFirewall> <my:ExtNAT></my:ExtNAT> <my:InterGSS>false</my:InterGSS> <my:ExtGSS>false</my:ExtGSS> </my:GSSGroup> </my:ProxyLayer><my:PageBreak></my:PageBreak></my:myFields>
Load it like this:
$xml = New-Object xml$xml.Load("c:\yourfile.xml")
This gives you the number of ProxyLayers:
@($xml.myFields.ProxyLayer).Count
And here are the layers:
PS > $xml.myFields.ProxyLayer
ExistingURL : falseNewURL : trueURL : int.esig.URL.comGSS :CSS :ACE : ACEDNS : DNSSSL : SSLServerTable : {my:ServerTable, my:ServerTable}ACEConfig : ACEConfigDNSGroup : DNSGroupGSSGroup : GSSGroup
ExistingURL : falseNewURL : trueURL : int.services.esig.URL.comGSS :CSS :ACE : ACEDNS : DNSSSL : SSLServerTable : {my:ServerTable, my:ServerTable}ACEConfig : ACEConfigDNSGroup : DNSGroupGSSGroup : GSSGroup
Hello Tobias,
Thank you very much, that is exactly what I needed, from here I should be able to extract the information I need on a per layer basis.
Thank you for your help, it is greatly appreciated
Pleasure...