adding XSD path in XML doc

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
suman27
Participant
Posts: 33
Joined: Wed Jul 15, 2009 6:52 am
Location: London

adding XSD path in XML doc

Post by suman27 »

Hi,

I need to edit incoming XML and add XSD location path to it in name space.
I tried doing it with XMLINPUT include name space. But it is not adding any name space. Had Given the same Xpath expression in both input and out put coulumns. Is it correct way. I need XSD location in XML so that I can Validate it.. Help me out.

Regards,
Suman.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

...being able to do this easily will depend a lot on the size of your xml document and the way that you are reading it....

..the simples method is to pass the content (the entire document) as a single column, through a Transformer (or Basic Transformer if you are in a Parallel Job) and then apply any variety of rich text functions that are available in UV/Basic for pulling apart strings and adding/concatenating new things. The header location is fairly easy to find as it will be added bytes immediately to the left of the second ">" in your document. I'd have to give it some thought, but probably some creative use of Field() and Index() and in a large concatenation expression will deliver what you are looking for.

This whole technique is vastly easier to do inside of a Server Job where you can use the Folder Stage if you are picking up the document from disk, but if you are reading the document from something like MQ, should work fine in EE, if the document is small enough to easily fit on the link.

If you are passing the document name from something like the External Source Stage, it may be possible to move the entire document into a single string by using another up front instance of the XMLInput Stage with a single column on its output (try a single slash in the Description property)....I haven't tried that, but it might work....then pass to a Transformer to do the string manipulation before passing to a second instance of the XMLInput Stage.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Ernie

I think he needs to know manully how to add it. Not sure.
Mamu Kim
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

good point...here's the idea...I'll leave it to you to explore the exact functions to use.....

Let's say you have a document whose initial lines look like this:

<?xml version="1.0" ?>
<Company>
(and so forth)

...and you want to get the SchemaLocation="C:\tmp\mySchema.xsd" inserted.

If your document comes from the Folder Stage (for example) and is in a column called myXMLContent, then you will have a Derivation in a Transformer that uses a function(s) to pull everthing up to the "y" in Company [everything prior the second '>' and concatenates [:] that to ' SchemaLocation="C:\tmp\mySchema.xsd" ' and then concatenates that to a ">" and everything in your incoming document column that follows it. This effectively "zaps" the xsd value into the header.

There may be other more elegant ways to do it, but this brute force method will work fine, provided the caveats noted earlier on size and such pass ok.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
suman27
Participant
Posts: 33
Joined: Wed Jul 15, 2009 6:52 am
Location: London

Post by suman27 »

Hi Ernie,
Thanks for looking into this,
I am reading XML from MQ server, and I want my XSD location as parameter. Doing String operation on XML is good idea,
But I am wondering if there is any option to add XSDpath in XML Input,XML Output or XML transformer stage.

Regards,
Suman.

eostic wrote:good point...here's the idea...I'll leave it to you to explore the exact functions to use.....

Let's say you have a document whose initial lines look like this:

<?xml version="1.0" ?>
<Company>
(and so forth)

...and you want to get the SchemaLocation="C:\tmp\mySchema.xsd" inserted.

If your document comes from the Folder Stage (for example) and is in a column called myXMLContent, then you will have a Derivation in a Transformer that uses a function(s) to pull everthing up to the "y" in Company [everything prior the second '>' and concatenates [:] that to ' SchemaLocation="C:\tmp\mySchema.xsd" ' and then concatenates that to a ">" and everything in your incoming document column that follows it. This effectively "zaps" the xsd value into the header.

There may be other more elegant ways to do it, but this brute force method will work fine, provided the caveats noted earlier on size and such pass ok.

Ernie
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Nope. It has to be "in" the document.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
Post Reply