GithubHelp home page GithubHelp logo

pwshreadxmlplist's Introduction

PwshReadXmlPList

PwshReadXmlPList is a project to process an XML PList document into a usable PowerShell object. The resulting object will depend on the PList document, but will commonly be composed of ordered dictionaries and/or arrays of common (basic) value types or further dictionaries or arrays.

An XML PList is a somewhat challenging document to process due to a lack of wrapping each dictionary (<dict>) item's key (<key>) and value in a separate node tree, requiring sequential sibling node processing.

ConvertFrom-Plist

The project provides one function, ConvertFrom-Plist to process an XML PList document as a pipeline input. You use typical PowerShell processes to read in the XML content of the PList, whether from a file or other sources, using the [xml] shortcut to convert the content to an XML object if not already sourced as such, prior to piping to ConvertFrom-Plist.

Parameters

  • plist (-plist)

    The parameter -plist may be used in place of pipeline input.

Examples

Example uses:

. '.\PList Reader.ps1' # import the ConvertFrom-Plist function to the current session
$pList = ConvertFrom-Plist -plist ([xml](Get-Content 'somefile.plist')) # read 'somefile.plist' file and convert the result to $pList
$grammar_plist = [xml](Get-Content PowerShellSyntax.tmLanguage) | ConvertFrom-Plist # read the PowerShell TextMate syntax grammar description file and convert the result to $grammar_plist

Handling of <data>

ConvertFrom-Plist handles PList <data> objects by preparing them into byte array ([byte[]]) objects. The data that is encoded in the byte arrays depends on the application that generated the PList document. You may need to provide further processing for these objects.

Notes

  • PowerShell scripting knowledge is required.
  • This project was initially created to aid in processing TextMate tmLanguage grammar files, primarily for conversion to other formats, such as JSON.
  • <key> is not currently handled at the root level, but this appears to be compliant with the XML PList DTD.

pwshreadxmlplist's People

Contributors

msftrncs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

golubenkoff

pwshreadxmlplist's Issues

The output is incorrect

Use the following code to see the value of a key. The output is incorrect

Sample file:
test.zip

$pList = [xml](get-content "C:\Users\Administrator\Desktop\test.plist") | ConvertFrom-Plist
$pList.ACPI.DSDT.Patches.find

out:
80
88
83
88
8
95
65
68
82
0
8
95
80
82
87
18
6
2
71
70
88
48
72
68
69
70
95
68
83
77
72
69
67
73

<data> Label processing error

thanks for the powershell tools!

I found a problem in using, < data > label processing error,

For example:


before:

<data>U0FUMA==</data>

after:

<string>83 65 84 48</string>

before:

				<key>Find</key>
				<data>RXh0ZXJuYWw=</data>

after:

				<key>Find</key>
				<array>
					<integer>69</integer>
					<integer>120</integer>
					<integer>116</integer>
					<integer>101</integer>
					<integer>114</integer>
					<integer>110</integer>
					<integer>97</integer>
					<integer>108</integer>
				</array>

My programming level, English expression is not very good,

so, I recorded a video demonstration: https://www12.zippyshare.com/v/CKLQBgMj/file.html

Related documents: https://www12.zippyshare.com/v/4VdpVBR0/file.html

This is a good tool. Thank you in advance

Planned Changes

I plan to make changes to the layout and operation of this function, similar to ConvertTo-PList.

  • Rename function to 'ConvertFrom-Plist'
  • Alter output so dictionaries are converted to [ordered] hashtables instead of PSCustomObjects.
  • Redesign and test for performance, using an internal static Class to handle the conversion of the XML to PowerShell object, to improve performance.

See: https://github.com/msftrncs/PwshReadXmlPList/tree/ConvertFrom-Plist

Empty elements returned without declared data type, causing incorrect behavior in downstream tools

Using the following code, a null label will be output incorrectly,
Sample file
test.zip

before:

                    <key>Base</key>
                    <string></string>

after:

                    		<key>Base</key>
				<dict>
				</dict>

before:

                    <key>ReplaceMask</key>
                    <data></data>

after:

				<key>ReplaceMask</key>
				<dict>
				</dict>

before:

            <key>Patch</key>
            <array/>

after:

		<key>Patch</key>
		<dict>
		</dict>

powershell code:

$pList = [xml](get-content "C:\Users\Administrator\Desktop\s1.plist") | ConvertFrom-Plist

$pList | ConvertTo-Plist -Indent "`t" -StateEncodingAs 'UTF-8' -Depth 6 | Set-Content 'C:\Users\Administrator\Desktop\s1-ok.plist' -Encoding 'UTF8'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.