Dynamic XSD/Schema ?

Hi all,

I have to cut and validate an XML file in the same time but I don’t how to do it …

In entries, I have :

  • myXMLFile.xml
  • XSDForMyXMLFile.xsd

And I want :

  • myRejectedNodeXMLFile.xml
  • myXMLFileA.xml
  • myXMLFileB.xml

For example :
If myXMLFile.xml is :

<Root>
<Header>
</Header>
<Data Value=><subData>..</subData></Data>
<Data Value=A><subData>..</subData></Data>
<Data Value=B><subData>..</subData></Data>
<Data Value=A><subData>..</subData></Data>
<Data Value=B><subData>..</subData></Data>
</Tail>
</Tail>
</Root>

I want to get those :
myRejectedNodeXMLFile.xml :

<Root>
<Header>
</Header>
<Data Value=><subData>..</subData></Data>
</Tail>
</Tail>
</Root>

myXMLFileA.xml :

<Root>
<Header>
</Header>
<Data Value=A><subData>..</subData></Data>
<Data Value=A><subData>..</subData></Data>
</Tail>
</Tail>
</Root>

myXMLFileB.xml :

<Root>
<Header>
</Header>
<Data Value=B><subData>..</subData></Data>
<Data Value=B><subData>..</subData></Data>
</Tail>
</Tail>
</Root>

So, if it’s possible, I would like to proceed like that :
1/ Make a service which takes for parameters (MyXSDGenerator) :

  • XSDForMyXMLFile.xsd
  • MyNodeName (Header, Data and Tail in my previous example)

And returns :

  • XSDForMyNodeName.xsd (XSDForHeader.xsd for example)

In brief, that service should be a kind of “XSD Generator”

2/ Make a service which takes for parameters (MyValidate) :

  • an XMLNode
  • an XSDFile.xsd

And returns :

  • a boolean isValid indicates if that node is conform to the schema
  • an XMLNode (same as entries)

The main service should look like this :

[ATTACH]108[/ATTACH]

So do you think that is possible to implement something like that ?

Thks in advance.
test.zip (13 KB)

Why do you think it is necessary to do this?

Mark

Do you have another method to submit ?

I’m opened.

I don’t want to make a specific implementation for each kind of treatment, I will have to do (different treatment = different file/different xsd)…

That’s why I want to make it that way… It’s (I think) the most “generic” treatment.
.
Obviously, I can make a specific Java development for each kind of treatment…

What does the pub.schema:validate built-in service not do that you want to do? When iterating over a document using getNextXMLNode you could validate that node using pub.schema:validate, the output of which is an array of validation errors. If there were any for the selected node, it should be added to the “bad nodes” list, if not it could be examined using pub.xml:queryXMLNode to see if it goes into the “A” pile or “B” pile.

I don’t understand the value of dynamically generating an XSD on the fly. If your doc types have been created from the XSD in the first place, you can dynamically set the “conformsTo” parm to validate against the correct one.

Maybe I’m missing something, but I would echo Rob’s oft repeated refrain “Don’t write it in java”.

Mark

Thks for your answer.

I know about the “Don’t write Java code” but something we don’t have the choice …

About pub.schema:validate I have try to “validate” node by node with my schema but it doesn’t work … but maybe I have done something wrong …

I have done something like that (I will update this post monday when i’ll go back to my office)

pub.file:getFile in stream mode
pub.xml:stringToXMLNode
pub.xml:xmlNodetoIterator with criteria as (Header, Data, Tail (like my example)
Repeat
[INDENT]pub.xml:getNextXMLNode
Branch on /next
[INDENT]$null:Exit
[/INDENT]pub.schema:validate with schema generate with XSDfile which describe the whole file
[/INDENT]pub.xml:freeXMLNode

But validate always returns false …
Do I make a mistake somewhere ?

Populate the conformsTo parm with the fully qualified name of a document type created from your XSD. I would create one doc type each for Header, Data and Tail and then populate conformsTo based on the name of the node.

You may need to the top level from the doc type and indent its children after generating it from the XSD.

Mark

Thks for help.

So I have tried to create a document type from my XSD for my header and my data but when I try to validate with those doc type, I got an exception which indicates that :

(note: In order to create my docs type, I generate them from a XSD schema and take off element that I don’t need.)

Any idea ?