I'm trying to read an rss feed using powershell and I can't extract a cdata-section within the feed
Here's a snippet of the feed (with a few items cut to save space):
<item rdf:about="http://philadelphia.craigslist.org/ctd/blahblah.html">
<title>
<![CDATA[2006 BMW 650I,BLACK/BLACK/SPORT/AUTO ]]>
</title>
...
<dc:title>
<![CDATA[2006 BMW 650I,BLACK/BLACK/SPORT/AUTO ]]>
</dc:title>
<dc:type>text</dc:type>
<dcterms:issued>2011-11-28T22:15:55-05:00</dcterms:issued>
</item>
And the Powershell script:
$rssFeed = [xml](New-Object System.Net.WebClient).DownloadString('http://philadelphia.craigslist.org/sss/index.rss')
foreach ($item in $rssFeed.rdf.item) { $item.title }
Which produces this:
#cdata-section
--------------
2006 BMW 650I,BLACK/BLACK/SPORT/AUTO
2006 BMW 650I,BLACK/BLACK/SPORT/AUTO
How do I extract the cdata-section?
I tried a few variants such as $item.title."#cdata-section" and $item.title.InnerText which return nothing. I tried $item.title | gm and I see the #cdata-section listed as a property. What am I missing?
Thanks.
Since you have multiple of those, the title property itself would be an array, so the following should work:
$rss.item.title | select -expand "#cdata-section"
or
$rss.item.title[0]."#cdata-section"
based on what you need.
Related
I am trying to create a table where I essentially have two headings of different cell size and the items in the table must follow the second heading, like this:
**Main Heading 1** | **Main Heading 2**
sub 11 | sub 12 | sub 13 | sub 14 | sub 21 | sub 22 | sub 23 | sub 24
item | item | item | item | item | item | item | item
...
I have tried with the following structure
<Table size="small" aria-label="stock-flow">
<TableHead>
<TableRow>
<TableCell>Main Heading 1</TableCell>
<TableCell>Main Heading 2</TableCell>
</TableRow>
<TableRow>
<TableCell>Sub 11</TableCell>
<TableCell>Sub 12</TableCell>
<TableCell>Sub 13</TableCell>
<TableCell>Sub 14</TableCell>
<TableCell>Sub 21</TableCell>
<TableCell>Sub 22</TableCell>
<TableCell>Sub 23</TableCell>
<TableCell>Sub 24</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Item 11</TableCell>
<TableCell>Item 12</TableCell>
<TableCell>Item 13</TableCell>
<TableCell>Item 14</TableCell>
<TableCell>Item 21</TableCell>
<TableCell>Item 22</TableCell>
<TableCell>Item 23</TableCell>
<TableCell>Item 24</TableCell>
</TableRow>
</TableBody>
</Table>
But that aligns Main heading 1 and Main Heading 2 above sub11 and sub12 and leaves 6 empty spaces after that.
I essentially want to have 2 "main" columns and a way to create whatever sizes of columns/rows I want in each of them.
EDIT: I found the answer, I have to use the colSpan property and give it a value of the amount of cells that I want to have underneath the main heading, so both headings get colSpan={4}
I found the answer, I have to use the colSpan property and give it a value of the amount of cells that I want to have underneath the main heading, so both headings get colSpan={4}
Related to PowerShell 5.1
I was playing around with XML to show how to handle conflicting namespaces. Here's the example I created:
<Employees>
<ms:Employee id='1' xmlns:ms="MicrosoftEmployees">
<FirstName>Bill</FirstName>
<LastName>Gates</LastName>
</ms:Employee>
<ms:Employee id='2' xmlns:ms="MicrosoftEmployees">
<FirstName>Paul</FirstName>
<LastName>Allen</LastName>
</ms:Employee>
<ap:Employee id='1' xmlns:ap="AppleEmployees">
<Name>Steve Jobs</Name>
</ap:Employee>
<ap:Employee id='2' xmlns:ap="AppleEmployees">
<Name>Steve Wozniak </Name>
</ap:Employee>
</Employees>
The scenario might be combining data from two different companies.
PowerShell demonstration program:
cls
$filename = "c:\XMLClass\IntroSamples\Sample05_Simpler_Namespace.xml"
[xml]$xmlDoc = Get-Content $filename
$xmlDoc.Employees.Employee[0]
$xmlDoc.Employees.Employee[1]
$xmlDoc.Employees.Employee[2]
$xmlDoc.Employees.Employee[3]
Output:
id ms FirstName LastName
-- -- --------- --------
1 MicrosoftEmployees Bill Gates
2 MicrosoftEmployees Paul Allen
1
2
Is there anyway to get a more logical output?
It seems like PowerShell locks into the first schema it sees for the Employee element, then cannot show the Name element of the Apple employees. This actually makes sense, but I was just checking to see if there is something fancier to handle this that I might be missing.
I know I could use SelectSingleNodes and XPath, but was just trying to see if and how PowerShell could handle this "out of the box".
If I reverse the code:
$xmlDoc.Employees.Employee[2]
$xmlDoc.Employees.Employee[3]
$xmlDoc.Employees.Employee[1]
$xmlDoc.Employees.Employee[0]
Then the output is:
id ap Name
-- -- ----
1 AppleEmployees Steve Jobs
2 AppleEmployees Steve Wozniak
1 ms:Employee
2 ms:Employee
Use format list to see all the properties. Format-table doesn't handle different sets of properties well.
$xmldoc.employees.employee | format-list
id : 1
ms : MicrosoftEmployees
FirstName : Bill
LastName : Gates
id : 2
ms : MicrosoftEmployees
FirstName : Paul
LastName : Allen
id : 1
ap : AppleEmployees
Name : Steve Jobs
id : 2
ap : AppleEmployees
Name : Steve Wozniak
PostgreSQL 9.2.4
I apologize if I added a duplicate topic, but I can't seem to figure it out (yet). I'd like to parse XML data which is stored in postgres table.
For example:
select program_information.description FROM program_information WHERE id = 8768787;
gives me output like:
<?xml version="1.0"?>
<ProgramInformation>
<BasicDescription>
<Title type="original">Zla smrt</Title>
<Synopsis length="short">Pet prijateljev, starih nekaj čez dvajset let, v samotni koči najde Knjigo mrtvih. S posnetka, ki so ga napravili arheologi, izvedo, da je bilo starodavno besedilo odkrito med kandarijskimi ruševinami sumerske civilizacije.</Synopsis>
<Keyword type="secondary"></Keyword>
<ParentalGuidance>
<mpeg7:ParentalRating href="rn:mpeg:MPAAParentalRatingCS:PG">
<mpeg7:Name>PG</mpeg7:Name>
</mpeg7:ParentalRating>
</ParentalGuidance>
<CreditsList>
<CreditsItem role="urn:tva:metadata:TVARoleCS:ACTOR">
<PersonName>
<mpeg7:GivenName>Bruce</mpeg7:GivenName>
<mpeg7:FamilyName>Campbell</mpeg7:FamilyName>
</PersonName>
</CreditsItem>
<CreditsItem role="urn:tva:metadata:TVARoleCS:ACTOR">
<PersonName>
<mpeg7:GivenName>Ellen</mpeg7:GivenName>
<mpeg7:FamilyName>Sandweiss</mpeg7:FamilyName>
</PersonName>
</CreditsItem>
<CreditsItem role="urn:tva:metadata:TVARoleCS:ACTOR">
<PersonName>
<mpeg7:GivenName>Betsy</mpeg7:GivenName>
<mpeg7:FamilyName>Baker</mpeg7:FamilyName>
</PersonName>
</CreditsItem>
<CreditsItem role="urn:tva:metadata:TVARoleCS:DIRECTOR">
<PersonName>
<mpeg7:GivenName>Sam</mpeg7:GivenName>
<mpeg7:FamilyName>Raimi</mpeg7:FamilyName>
</PersonName>
</CreditsItem>
</CreditsList>
<ReleaseInformation>
<ReleaseDate>
<Year>1981</Year>
</ReleaseDate>
</ReleaseInformation>
</BasicDescription>
<AVAttributes>
<AudioAttributes>
<NumOfChannels>2</NumOfChannels>
</AudioAttributes>
</AVAttributes>
</ProgramInformation>
So what I'd like is a parsed output of that output in separate columns (title, synopsis, ratings, actors, etc.)
So what I'd like is an output like
+----------+-------------+----------------+
| Title | Synopsis | ParentalRating |
+----------+-------------+----------------+
| my title | some descr | rating |
+----------+-------------+----------------+
I've tried with xpath but so far a dead end... :/
Can anyone guide me to correct query? Thank you!
M
Your XML document misses a namespace declaration. Is it supposed to be like that? I manually added a namespace at <ProgramInformation> and it worked ..
<ProgramInformation xmlns:mpeg7="http://mpeg7.io">
.. with the following query:
SELECT
XPATH('//BasicDescription/Title/text()', t.xml) AS title,
XPATH('//BasicDescription/Synopsis/text()', t.xml) AS synopsis,
XPATH('//mpeg7:ParentalRating/mpeg7:Name/text()', t.xml,ARRAY[ARRAY['mpeg7', 'http://mpeg4.io']]) AS parentalRating
FROM t;
title | synopsis | parentalrating
--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------
{"Zla smrt"} | {"Pet prijateljev, starih nekaj čez dvajset let, v samotni koči najde Knjigo mrtvih. S posnetka, ki so ga napravili arheologi, izvedo, da je bilo starodavno besedilo odkrito med kandarijskimi ruševinami sumerske civilizacije."} | {PG}
(1 Zeile)
I have a list with a large number of datapoints. (130 columns, 31000 items). I run certain scripts to data-mine and/or update that info. One trick I use to speed up processing time is to pull the whole list into an array at the beginning. This allows powershell to query the array instead of going back to the list each time.
In these scripts I'm usually only searching a few of the fields, making it inefficient to pull all 130+ columns I'm hoping looking for a way to limit what fields are being pulled in.
In the below script, everything works fine until I add the "Select" part of the query. I then get an error of "Unable to index into an object of type System.Management.Automation.PSObject".
Any pointers are greatly appreciated!
$oList = $Web2.Lists["Forecasting data source"]
$aList = $Web.Lists["ArrayTest"]
filter MyFilter {if ($_["CHGTaskRegion"] -eq "Syracuse") {$_}}
$list = $oList.Items | MyFilter | Select ["CHGTaskFacility"],["CHGTicketNumber"]
$list | ForEach-Object {
$ListItem = $aList.Items.Add()
$ListItem["Title"] = [string]$_["CHGTaskFacility"]
$ListItem["Number"] = [string]$_["CHGTicketNumber"]
$ListItem.Update()
}
EDIT:
This is way after the fact but I saw this old post of mine and figured it was worth coming back to. The proper method isn't actually to pull in the whole list and then search it. The right way is to simply get just the items you wanted in the first place using a CAML query. Like so:
$spqQuery = New-Object Microsoft.SharePoint.SPQuery
$spqQuery.Query =
" <Where>
<Eq>
<FieldRef Name='CHGTaskRegion' />
<Value Type='File'>Syracuse</Value>
</Eq>
</Where>"
$spqQuery.ViewFields = "<FieldRef Name='CHGTaskFacility' /><FieldRef Name='CHGTicketNumber' />"
$spqQuery.ViewFieldsOnly = $true
$splListItems = $splList.GetItems($spqQuery)
Have you tried:
$list = $oList.Items | MyFilter | Select {$["CHGTaskFacility"]}, {$["CHGTicketNumber"]}
Add underscore after dollar signs. For some reason _ is not showing up in the code above.
/Pawel
I think the code should be :
$list = $oList.Items | MyFilter | Select CHGTaskFacility,CHGTicketNumber
The way you wrote it, means that you tried to type cast, anything between [ ] being the type.
And so it got confused.
CHGTaskFacility and CHGTicketNumber are properties of the $list of objects, and so Select CHGTaskFacility,CHGTicketNumber is sufficient for Powershell to select them.
UPDATE:
I think the filter code may be incorrect:
filter MyFilter {if ($_."CHGTaskRegion" -eq "Syracuse") {$_}}
I am using MVC razor 5
I'm making managment page to add SelectList values (like Car models)
I have values in my car models table:
--------------------------------------
Id | Name | Deleted
1 | BMW | False
2 | Audi | False
3 | Ford | False
4 | BMW5 | False
5 | SEAT | False
--------------------------------------
When i add new value id becomes 130++
I have noticed that my main class last records Id is 130.
And when I insert a record in car model class Id is the nextval(Id) of main class
But these two tables does not share same Controller or so...
All sessions are closed by transaction.Commit() so session closes.
What may be wrong?
Nhibernate class mapping:
<class name="web_nt.Models.Class.CarModel" table="car_model" schema="public">
<id name="Id" column="id" type="int">
<generator class="native" />
</id>
<property name="model_name" />
<property name="deleted" />
</class>
It was generator class fault.
To use postgres sequence I needed to specify it (NHibernate does not always catch it itself)
<generator class="sequence">
<param name="sequence">car_model_id_sequence</param>
</generator>