473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Parse Xml Schema

I have a Xml schema like the this:

....
<schema xmlns = "http://www.w3.org/2001/XMLSchema"
targetNamespace = "http://www.ipdr.org/namespaces/ipdr"
xmlns:ipdr = "http://www.ipdr.org/namespaces/ipdr"
version = "3.0"
elementFormDefault = "qualified"
attributeFormDefault = "unqualified">
<include schemaLocation = "IPDRDoc3.0.xsd"/>
<element name = "day" type = "string"/>
<element name = "size" type = "int"/>
<complexType name = "IPDR-TEST-Type">
<complexContent>
<extension base = "ipdr:IPDRType">
<sequence>
<element ref = "ipdr:day"/>
<element ref = "ipdr:size" minOccurs="0"/>
</sequence>
</extension>
</complexContent>
</complexType>
</schema>

I would like to be able write code which would output the following to me:

IPDR-TEST-TYPE
NAME DATA-TYPE MIN-OCCURANCE
Day string 1
size int 0

I've tried the following:

reader = new XmlTextReader(getIPDRStructure.FileName);
schema = XmlSchema.Read(reader,null);

foreach(XmlSchemaObject elem in schema.Items)
{
if(elem is XmlSchemaComplexType)
{
XmlSchemaComplexType complexType = (XmlSchemaComplexType)elem;

// but complexType.Particle here is null
Anybody know how I can do this?
Nov 12 '05 #1
1 2652
Steve,
There is a problem with your schema definition. If you change your schema
definition to just <schema> then the following XSLT will work:
Regards,
Dan

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<!-- begin -->
<xsl:template match="//schema">
<xsl:apply-templates select="complexType"/>
</xsl:template>
<!-- complexType -->
<xsl:template match="complexType">
<xsl:value-of select="@name"/>
<xsl:text> </xsl:text>
<xsl:text>NAME </xsl:text>
<xsl:text>DATA TYPE </xsl:text>
<xsl:text>MIN-OCCURANCE </xsl:text>
<xsl:for-each select="complexContent/extension/sequence/element">
<xsl:text> </xsl:text>
<xsl:value-of select="substring-after(@ref,':')"/>
<xsl:text> </xsl:text>
<xsl:call-template name="GetDataType">
<xsl:with-param name="elementName" select="substring-after(@ref,':')"/>
</xsl:call-template>

<xsl:text> </xsl:text>
<xsl:value-of select="@minOccurs"/>
</xsl:for-each>
</xsl:template>

<!-- get the data type -->
<xsl:template name="GetDataType">
<xsl:param name="elementName"/>
<xsl:value-of select="preceding::element[@name=$elementName]/@type"/>
</xsl:template>

</xsl:stylesheet>

"Steve" <sh*****@tssg.org> wrote in message
news:ca**************************@posting.google.c om...
I have a Xml schema like the this:

...
<schema xmlns = "http://www.w3.org/2001/XMLSchema"
targetNamespace = "http://www.ipdr.org/namespaces/ipdr"
xmlns:ipdr = "http://www.ipdr.org/namespaces/ipdr"
version = "3.0"
elementFormDefault = "qualified"
attributeFormDefault = "unqualified">
<include schemaLocation = "IPDRDoc3.0.xsd"/>
<element name = "day" type = "string"/>
<element name = "size" type = "int"/>
<complexType name = "IPDR-TEST-Type">
<complexContent>
<extension base = "ipdr:IPDRType">
<sequence>
<element ref = "ipdr:day"/>
<element ref = "ipdr:size" minOccurs="0"/>
</sequence>
</extension>
</complexContent>
</complexType>
</schema>

I would like to be able write code which would output the following to me:

IPDR-TEST-TYPE
NAME DATA-TYPE MIN-OCCURANCE
Day string 1
size int 0

I've tried the following:

reader = new XmlTextReader(getIPDRStructure.FileName);
schema = XmlSchema.Read(reader,null);

foreach(XmlSchemaObject elem in schema.Items)
{
if(elem is XmlSchemaComplexType)
{
XmlSchemaComplexType complexType = (XmlSchemaComplexType)elem;

// but complexType.Particle here is null
Anybody know how I can do this?

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave Kuhlman | last post by:
Suppose that I have content that looks like what I've included at the end of this message. Is there something in the standard Python library that will help me parse it, break into the parts...
1
by: Anna | last post by:
Hi all. I need to parse an XML Schema and get the following information out of it: list of elements allowed in schema list of attributes for each element - which are required and which optional...
0
by: heiko | last post by:
Hi, I have written a program for parsing XML data with Xerces and C++. There are still two things, for which I need help: I want to validate a XML file with a schema, given by my xsd-file. ...
0
by: Bryan Ax | last post by:
I currently have two versions of a dtd (1.01 and 1.11) that both contain the following entity: v1.01: <!ENTITY % doc-type "A | B | Other"> v1.11: <!ENTITY % doc-type "A | B | C | Other"> ...
5
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML...
1
by: Confused XML hacker | last post by:
My application needs to be able to parse and validate either a DTD or schema based document without knowing in advance which form of grammar a document is using. (New documents presented to my...
0
by: nithyasri | last post by:
How to Parse Xml schema using .NET and get an object model? I need to parse an Xml schema and display it as a tree structure in dot net. How do i do it? Any help will be appreciated.
5
by: Abhinay | last post by:
hi, I wrote function to validate my xml file against specified schema, it works fine in most of the cases, but some times validation failed because following parse Error. The process cannot...
6
by: sushmaraghu | last post by:
Can anyone tell me how to validate xml files which are not W3C complaint in C#.NET. my xml file is of this format <?xml version="1.0" ?> <Test xmlns="x-schema:MySchema.xml"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.