473,396 Members | 1,724 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,396 software developers and data experts.

defaults and range checks from multiple xsd

1
Hi,

I have a weird requirement and since i have never worked on xml, xsd and python i am not understanding how to go about it.
There will be 2 xsd files containing parameters(structure), (may or maynot have)default values for them and range values for them. The xml file will contain values for these parameters and (may or maynot) have values for optional parameters.

So in the example file below, P_B.1 is an element, which has a value "1" in xml file. I need to get this value and i need to check whether the value fits into the range mentioned in both xsd1 and xsd2(which is the min and max values under restriction). If it fits then i need to put it into my global data structure i maintain to store these parameters. P_B.A1 is an attribute which is optional,so the value for it is not present in xml. In such cases i need to go and first pick up its default value in xsd1, if the value for the attribute is not present then go to xsd2 and pick its default value. Now consider, i picked up the default value from xsd1, after this i need to check whether the value i picked up fits the range(min and max under restriction for the element) in both xsd1 and xsd2 and if it correctly fits the range in both xsd, then fill the value into my global data structure.

I understand that tools like pyxbgen provides me bindings for the xsd files i have. But i am not able to visualize how i will be able to use them. my questions are:
1. is it better to parse both the xsd with simple parsers and then parse the xml content then create my datastructure, which is the brute force or the raw way. if so what are the good xsd parsers available in python?
2. Or is it a better idea to create bindings for both my xsd, then retrieving the parameter values from the xml file using both these xsd bindings. then generate a new xml filling up all the optional parameters avaiable with default values from the xsd. later, validate the new xml again with the bindings previously generated for the xsd files.
3. Or is there some other better way.

thanks in advance.
The sample xsd and xml is given below:

Expand|Select|Wrap|Line Numbers
  1. XSD:
  2.  
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  5.     <xs:element name="P_ROOT">
  6.         <xs:annotation>
  7.             <xs:documentation>...</xs:documentation>
  8.         </xs:annotation>
  9.         <xs:complexType>
  10.             <xs:element name="P_B" minOccurs="0" maxOccurs="1500">
  11.                 <xs:annotation>
  12.                     <xs:documentation>....</xs:documentation>
  13.                 </xs:annotation>
  14.                 <xs:complexType>
  15.                     <xs:sequence>
  16.                         <xs:element name="P_B.1" type="xs:int" maxOccurs="5" use="required">
  17.                             <xs:annotation>
  18.                                 <xs:documentation>...</xs:documentation>
  19.                             </xs:annotation>
  20.                             <xs:restriction base="xs:int">
  21.                                 <xs:minInclusive value="1"/>
  22.                                 <xs:maxInclusive value="5"/>
  23.                             </xs:restriction>
  24.                         </xs:element>
  25.                         <xs:element name="P_B.2" type="xs:int" maxOccurs="5" use="required">
  26.                             <xs:annotation>
  27.                                 <xs:documentation>...</xs:documentation>
  28.                             </xs:annotation>
  29.                             <xs:restriction base="xs:int">
  30.                                 <xs:minInclusive value="1"/>
  31.                                 <xs:maxInclusive value="5"/>
  32.                             </xs:restriction>
  33.                         </xs:element>
  34.                     </xs:sequence>
  35.                     <xs:attribute name="P_B.A1" default="1" use="optional">
  36.                         <xs:annotation>
  37.                             <xs:documentation>...</xs:documentation>
  38.                         </xs:annotation>
  39.                         <xs:simpleType>
  40.                             <xs:restriction base="xs:int">
  41.                                 <xs:minInclusive value="1"/>
  42.                                 <xs:maxInclusive value="5"/>
  43.                             </xs:restriction>
  44.                         </xs:simpleType>
  45.                     </xs:attribute>            
  46.                 </xs:complexType>
  47.             </xs:element>
  48.         </xs:complexType>
  49.     </xs:element>
  50. </xs:schema>
  51.  
  52. XML:
  53. <?xml version="1.0" encoding="UTF-8"?>
  54. <P_ROOT>
  55.     <P_B>
  56.         <P_B.1>1</P_B.1>
  57.         <P_B.2>2</P_B.2>
  58.     </P_B>
  59. </P_ROOT>
  60.  
Apr 30 '13 #1
1 1707
bvdet
2,851 Expert Mod 2GB
The example xsd file you posted appears to be valid xml except there is no opening tag for closing tag "</xs:sequence>". Was this a copy/paste error?

I have been using xml.dom.minidom for xml parsing for a long time, but there are several other modules for parsing xml including ElementTree.
May 1 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Fernando Nasser | last post by:
Multiple database services and multiple versions on Red Hat Linux systems The way it works is that we require a specific service script for each database service (that is listening on each port)....
1
by: epigram | last post by:
I'm trying to use the ASP.NET validators to check some client-side business rules. I've got two ASP TextBox controls (call them tbxYear1 and tbxYear2) used to enter a range of years. I've got a...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
1
by: dailem | last post by:
I'm trying to create a query that will run with criteria that includes the most recent eight weeks of data (by week number). The problem that I can't get around is how I handle the first 7 weeks...
1
by: grumpyone | last post by:
I'm looking for a method to enter and retain a start date and end date for use with a macro that runs 11 month-end reports that each require the same start date and end date. FYI- currently, the...
2
by: tyv | last post by:
Hi, I have a bug on my website that I'm trying to fix. I have filters (drop down menus and click-calendar date range) that narrow down searches on my website by pulling out the information from...
0
by: tyv | last post by:
Hi, I have a bug on my website that I'm trying to fix. I have filters (drop down menus and click-calendar date range) that narrow down searches on my website by pulling out the information from...
0
by: sparks | last post by:
I was using the keypress with an option group If Me.ActiveControl.ControlType = acOptionGroup Then If KeyAscii >= 48 And KeyAscii <= 51 Then Me.ActiveControl.Value = Chr(KeyAscii) End If End...
2
by: Chriskim | last post by:
I wrote a program that uses PyQt4, mathplotlib to generates graphs. I made a executable file using Py2exe. Everything is working fine, but when I exit from my program, a window message pops...
1
by: Karen Rosen | last post by:
This is my first program of any sort I am getting this error File "karenrosen5.py", line 162, in <module> record.append(triad("NoReleve",line)) File "karenrosen5.py", line 115, in triad...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.