Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom XML tags possible?

Status
Not open for further replies.

herman404

Programmer
Sep 4, 2007
1
GB
Hi everyone,

I was wondering if it was possible to have a XML schema that can specify a different type of XML element. For example, we have an XML file that has this:

<xml header>
<body1>data</body1>
<body2>moredata</body2>
</xml header>

My question is that can we write a schema that can allow for XML files to have the different tags based on other stuff in the file. In order words, can we write a schema that works with the below example:

<xml header>
<body1>data</body1>
<data>stuff</data>
</xml header>

Thanks
 
So you want to constrain the name of the second child node based on the value of the first node?

This is not possible (as far as I know) with XML schema. You will need to use schematron. Something along the lines of:
Code:
<?xml version="1.0"?>
<schema xmlns="[URL unfurl="true"]http://www.ascc.net/xml/schematron">[/URL]
  <pattern name="Structural Validation">
    <rule context="xmlHeader">
      <assert test="local-name(*[2]) = body1">
        Second child node name must be the value of the body1
      </assert>
      .....

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top