PDA

View Full Version : Upcoming XML Export and Printing


EightBitz
November 4th, 2016, 11:50 PM
There was a recent post by Rob where he indicated there was an upcoming export feature for XML, and if nothing else, this would allow us to print. This offers the possibility that we'll have to roll our own print formatting. Not something I'm thrilled about, but hey, I'll take what I can get.

I've been poking around with XML features in PowerShell, and some of it is easier than I thought it would be while some of it is still a bit frustrating. I'm not a professional programmer, but I dabble, and I know there are others who wish to print, so I'm sharing what I'm learning in my struggles. If anyone else with more programming experience wishes to chime in, I'm all for that.

If you're going to follow along with me, I suggest loading the PowerShell ISE. It's not installed by default, but you can install it through the "Add or remove programs" control panel and selecting "Turn Windows Features on or off." Find "PowerShell ISE", and select it. (I'm assuming you're using Windows 8 or Windows 10.)

And just to clarify, this isn't meant to be an in-depth, comprehensive tutorial. I'm learning as I go, so this is a very basic introduction for myself that I'm sharing with you.

First of all, importing an XML file into PowerShell as an XML object is rather easy. To practice, I'm working with a Hero Lab portfolio, hence my variable name in the following code snippet. I'm also using a Mutants and Masterminds 3E portfolio with multiple characters.

(Paste this in the top half of the ISE window.)

[xml]$Portfolio = Get-Content -Path <filename>


That's it. That loads the file as an XML object. Click the green play button to run the script.
Now, in the bottom window, you can type "$Portfolio" and press the enter key. You'll see the child nodes ("xml" and "document") as column headers.

Now type "$Portfolio.document.public" (I'm skipping ahead with the child nodes), and you'll see the child nodes for program, localization and character. Under the character column, you'll see the list of character names in curly brackets. Mine have spaces in the names (e.g. "The Rook").

So now, in the top half, I can add the following code to the script:


$Rook = $Portfolio.document.public.character | Where-Object {$_.name -eq "The Rook"}


Now, if I type $Rook in the bottom half of the ISE window, I can see a list of the child nodes and their values for this single character.

Now, say I want to get The Rook's attributes. In Mutants and Masterminds 3E, the attributes are Strength, Stamina, Agility and Dexterity. And for each attribute, the available elements are: text, base, modified, cost.

So if I want to get The Rook's strength, I can add the following code to the script.


$Strength = $Rook.attributes.attribute | Where-Object {$_.name -eq "Strength"}


Now, in the bottom half of the ISE window, I can type $Strength, and I'll see the different values. Or I can type $Strength.text, $Strength.base, $Strength.modified, or Strength.cost.

This is basically how you can drill-down through the XML object to get the values you want. To see the full hierarchy, you can load the XML file into UltraEdit (License required) or NotePad++ (Free) or something similar.

I wrote a recursive function that does kind of a raw text dump. It's not pretty, but if you want to play with the function, here it is:


Function ShowXML($PassedObject,$PassedOutput,$PassedIndent) {
"$PassedIndent### " + $PassedObject.name + " ###" >> $PassedOutput
if ($PassedObject.innertext -ne "") {
$PassedIndent + $PassedObject.innertext >> $PassedOutput
} elseif ($PassedParam.text -ne "") {
$PassedIndent + $PassedObject.text >> $PassedOutput
} # if ($PassedObject.innertext)

if ($PassedObject.HasChildNodes) {
$PassedIndent = $PassedIndent + " "
foreach ($Child in $PassedObject.ChildNodes) {
ShowXML $Child $PassedOutput $PassedIndent
} # foreach ($Child in $PassedObject.ChildNodes)
} # if ($PassedObject.HasChildNodes)

} # Function ShowXML

# Main Script Starts Here
$InputFile = "<Original XML filename>"
$OutputFile = "<File to contain the raw dump>"
[xml]$Portfolio = Get-Content -Path $InputFile
"XML Output" > $OutputFile
$Indent = ""
ShowXML $Portfolio $OutputFile $Indent

Viking2054
November 5th, 2016, 12:04 AM
It may be a bit premature, except as a learning exercise. Besides, most of this is probably handled best with a CSS (cascading style sheet) and a web browser. There is another format you can use, but I'm betting the CSS format is the way to go for printing.

We would probably need LWD to provide us with the xml tags they are using for differentiating the various pieces of information though.

EightBitz
November 5th, 2016, 12:18 AM
It may be a bit premature, except as a learning exercise. Besides, most of this is probably handled best with a CSS (cascading style sheet) and a web browser. There is another format you can use, but I'm betting the CSS format is the way to go for printing.

We would probably need LWD to provide us with the xml tags they are using for differentiating the various pieces of information though.

Nothing wrong with a learning exercise. :-)

kbs666
November 5th, 2016, 08:39 AM
Once we find out how the XML is going to be formatted I can put together a basic CSS to allow plain viewing and printing. People should be able to customize that into handouts and other things pretty easily.

ShadowChemosh
November 5th, 2016, 09:50 AM
What you would really want to look at is XSLT tools designed to translate XML into something else like HTML. XSLT and XQuery where made to do exactly this to translate the XML Data into readable forms.

Similar to HL and Custom Output the RW output "may" even be able to call the XSLT directly for you making it even easier. Plus "Custom Output" options could be listed as things to download from the Content Market. Meaning you could have different output for different styles. Need it like a book format or a statblock could have different "Output" options to select.

EightBitz
November 5th, 2016, 12:04 PM
Cool. I appreciate all the input. Really looking forward to finally being able to print, and to whatever can make that easier.

rob
November 5th, 2016, 01:49 PM
We will be providing TWO distinct output formats. One is intended exclusively for importing content back into RW. This one will be for hardcore users only. The other is targeted specifically for users who just want to consume their content in a simpler, more streamlined manner - like PRINTING. The two formats will be VERY similar to each other, but they will diverge in areas where it makes sense based on the intended use. And, yes, there will be a formal XSD of the format.

We'll be sharing more details on this stuff in the not-to-distant future...

EightBitz
November 5th, 2016, 01:53 PM
We will be providing TWO distinct output formats. One is intended exclusively for importing content back into RW. This one will be for hardcore users only. The other is targeted specifically for users who just want to consume their content in a simpler, more streamlined manner - like PRINTING. The two formats will be VERY similar to each other, but they will diverge in areas where it makes sense based on the intended use. And, yes, there will be a formal XSD of the format.

We'll be sharing more details on this stuff in the not-to-distant future...

A much appreciated reply, Rob. Thank you.

DaFranker
November 6th, 2016, 03:14 PM
We will be providing TWO distinct output formats. One is intended exclusively for importing content back into RW. This one will be for hardcore users only. The other is targeted specifically for users who just want to consume their content in a simpler, more streamlined manner - like PRINTING. The two formats will be VERY similar to each other, but they will diverge in areas where it makes sense based on the intended use. And, yes, there will be a formal XSD of the format.

We'll be sharing more details on this stuff in the not-to-distant future...

Oh! That's epic news, since I was under the impression the export/import would be fully limited to exporting to/from Realms and wouldn't be usable to produce external formats yet.

Heh, any chance this will let the more enterprising among us cook up their own Player Web View conversion tool? I didn't catch from previous posts whether the export tools would allow us to pick Revealed content or exclude hidden snippets and other GM-only elements from an export.

rob
November 6th, 2016, 04:08 PM
Heh, any chance this will let the more enterprising among us cook up their own Player Web View conversion tool? I didn't catch from previous posts whether the export tools would allow us to pick Revealed content or exclude hidden snippets and other GM-only elements from an export.

Yes, this will be possible. Limiting the export to only revealed content is an important aspect of the mechanism.

MaxSupernova
November 7th, 2016, 09:38 AM
WHOOHOOOO!


And, I repeat, with great gusto and joy:

WHOOOHOOO!

DaFranker
November 7th, 2016, 04:03 PM
Yes, this will be possible. Limiting the export to only revealed content is an important aspect of the mechanism.

...

WHOOHOOOO!


And, I repeat, with great gusto and joy:

WHOOOHOOO!

And once more for effect: WHOOHOOOO!