Perl XML parser to extract the default values of the optional attributes fromt the xsd file - perl

I need to parse an XML file through a perl script. While parsing the file, I need to validate it with the corresponding xsd(schema definition) file. The xsd file contains some optional attribute with a default value being provided. I have to parse the xml file in such a way so that I should be able to fetch the default value for all the attribute that are not present in the XML(from xsd). The issue is that I couldn't find any appropriate parser in perl for this Job.I could find a parser that is able to validate the file but couldn't get the default value of attributes that are not present the XML.
Can you please suggest me any parser/module that can help me in getting the required data.
Note: I need the values of the attributes that are not present in the XML to make a complete record for database insertion.
Thanks for your time,

You might want to take a look at XML::Compile. It appears to me that the default values feature is supported, but I've never actually used the module at all.

You could also change the database schema so all fields have defaults.

Related

How to make a section optional when mapped to optional data in a Word OpenXml Part?

I'm using OpenXml SDK to generate word 2013 files. I'm running on a server (part of a server solution), so automation is not an option.
Basically I have an xml file that is output from a backend system. Here's a very simplified example:
<my:Data
xmlns:my="https://schemas.mycorp.com">
<my:Customer>
<my:Details>
<my:Name>Customer Template</my:Name>
</my:Details>
<my:Orders>
<my:Count>2</my:Count>
<my:OrderList>
<my:Order>
<my:Id>1</my:Id>
<my:Date>19/04/2017 10:16:04</my:Date>
</my:Order>
<my:Order>
<my:Id>2</my:Id>
<my:Date>20/04/2017 10:16:04</my:Date>
</my:Order>
</my:OrderList>
</my:Orders>
</my:Customer>
</my:Data>
Then I use Word's Xml Mapping pane to map this data to content control:
I simply duplicate the word file, and write new Xml data when generating new files.
This is working as expected. When I update the xml part, it reflects the data from my backend.
Thought, there's a case that does not works. If a customer has no order, the template content is kept in the document. The xml data is :
<my:Data
xmlns:my="https://schemas.mycorp.com">
<my:Customer>
<my:Details>
<my:Name>Some customer</my:Name>
</my:Details>
<my:Orders>
<my:Count>0</my:Count>
<my:OrderList>
</my:OrderList>
</my:Orders>
</my:Customer>
</my:Data>
(see the empty order list).
In Word, the xml pane reflects the correct data (meaning no Order node):
But as you can see, the template content is still here.
Basically, I'd like to hide the order list when there's no order (or at least an empty table).
How can I do that?
PS: If it can help, I uploaded the word and xml files, and a small PowerShell script that injects the data : repro.zip
Thanks for sharing your files so we can better help you.
I had a difficult time trying to solve your problem with your existing Word Content Controls, XML files and the PowerShell script that added the XML to the Word document. I found what seemed to be Microsoft's VSTO example solution to your problem, but I couldn't get this to work cleanly.
I was however able to write a simple C# console application that generates a Word file based on your XML data. The OpenXML code to generate the Word file was generated code from the Open XML Productivity Tool. I then added some logic to read your XML file and generate the second table rows dynamically depending on how many orders there are in the data. I have uploaded the code for you to use if you are interested in this solution. Note: The xml data file should be in c:\temp and the generated word files will be in c:\temp also.
Another added bonus to this solution is if you were to add all of the customer data into one XML file, the application will create separate word files in your temp directory like so:
customer_<name1>.docx
customer_<name2>.docx
customer_<name3>.docx
etc.
Here is the document generated from the first xml file
Here is the document generated from the second xml file with the empty row
Hope this helps.

PHPmailer: attaching a session variable to an email

Due to the fact that I have to create a PDF on my server using the uniqid() function, I must subsequently refer to it as a PHP variable in the rest of my code.
The variable that I create for it is a session variable. I later refer to this session variable in a separate file, which contains my PHPmailer code. I use the following line to attach the session variable to the mail:
$mail->AddStringAttachment($_SESSION[$attachment], "attachment.pdf");
The mail is sent correctly with a PDF attached, called attachment.pdf. However, this attached file, attachment.pdf, is empty. This is despite the fact that the PDF on the server, which the session variable refers to, contains the complete set of data. If I attach the name of the PDF, instead of the session variable, it works correctly.
I don't know why the use of a session variable when attaching the PDF is resulting in an empty file being sent. If anybody may be able to explain why this is happening, or suggest an alternative solution, I would greatly appreciate it!
I'm guessing that $_SESSION[$attachment] contains the name of your generated PDF file, so what you are doing here is attaching the name of the file as an attachment, rather than the file itself. You should probably be using this instead:
$mail->AddAttachment($_SESSION[$attachment], "attachment.pdf");

Parsing USS XML file in Cobol?

I am using the Cobol XML Parser to parse an xml document that originated from the HFS (USS) file system through batch JCL.
My problem is that the XML Parser is returning "XML DOCUMENT ERROR 0000000317" which seems to be an encoding issue.
Does anyone know how to get past this?
Thanks
You will need to ensure that the encoding tag on the XML declaration is valid and agrees with what the actual document is. You will also need to make sure that the LPAR you are running on has the proper code page conversions defined in Unicode Conversion Services for z/OS.

How do I append text to an existing XML file without rewriting the entire document?

I have a large amount of data in an XML file, and I'd like to append data to this file without rewriting it every time. I already know how to write the entire file out, but I'm struggling with how to append data to this file. Do you have a suggestion for how to do this?
XML isn't a good format for this - if you append to a previously-complete document, it's no longer a complete document.
One option (depending on the APIs available to you) is not to write the root tag or document declaration, but to fake them when you read the file. So you'd have:
Fake document declaration
Fake root open tag
Real data from the file
Fake root close tag
Then you can just append elements to the end of your file at will. It will depend on what you're trying to do with this file though - and whether you can fake a stream input which effectively "tops and tails" the real data in the file.

How to add an extra plist property using CMake?

I'm trying to add the item
<key>UIStatusBarHidden</key><true/>
to my plist that's auto-generated by CMake. For certain keys, it appears there are pre-defined ways to add an item; for example:
set(MACOSX_BUNDLE_ICON_FILE ${ICON})
But I can't find a way to add an arbitrary property.
I tried using the MACOSX_BUNDLE_INFO_PLIST target property as follows: I'd like the resulting plist to be identical to the old one, except with the new property I want, so I just copied the auto-generated plist and set that as my template. But the plist uses some Xcode variables, which also look like ${foo}, and CMake grumbles about this:
Syntax error in cmake code when
parsing string
<string>com.bedaire.${PRODUCT_NAME:identifier}</string>
syntax error, unexpected cal_SYMBOL,
expecting } (47)
Policy CMP0010 is not set: Bad
variable reference syntax is an error.
Run "cmake --help-policy CMP0010"
for policy details. Use the
cmake_policy command to set the
policy and suppress this warning. This
warning is for project developers.
Use -Wno-dev to suppress it.
In any case, I'm not even sure that this is the right thing to do. I can't find a good example or any good documentation about this. Ideally, I'd just let CMake generate everything as before, and just add a single extra line. What can I do?
Have you looked into copying the relevant *.plist.in file in /opt/local/share/cmake-2.8/Modules (such as MacOSXBundleInfo.plist.in), editing it to put <key>UIStatusBarHidden</key><true/> (or #VAR_TO_REPLACE_BY_CMAKE#), and adding the directory of the edited version in the CMAKE_MODULE_PATH?
If you have CMake installed as an app bundle, then the location of that file is /Applications/CMake.app/Contents/share/cmake-N.N/Modules
You can add your values using # and pass #ONLY to configure_file.
Unfortunately there is no simple way to add custom line to generated file.