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

xml generator

Hi All,

I have an xml file with the structure below.I'd like to create dynamic
number of xml files from this file based on <subreport> elements.each XML
file contains
subreport element only .for instance if there are 4 <subreport> elements
,I'd like to create 4 different xml files and I want them to be named based
on <Ship_Via> child value in each <subreport> element.

Is there somebody who can give me an idea?
thanks for your help.
ALI
====XML file====
<?xml version="1.0"?>
<report>
<subreport>
<heading>
<Sales_Order_Lbl>Sales Order1</Sales_Order_Lbl>
<Ship_Via>10-TR</Ship_Via>
</heading>
<detail_values>
<Ln>2</Ln>
<Item_Number>12</Item_Number>
<Producer_Address>Address1:</Producer_Address>
</detail_values>
<footer>
<Total_Plts_Lbl>Total2</Total_Plts_Lbl>
<Total_Invoice>0.00</Total_Invoice>
</footer>
</subreport>
<subreport>
<heading>
<Sales_Order_Lbl>Sales Order2</Sales_Order_Lbl>
<Ship_Via>11-TR</Ship_Via>
</heading>
<detail_values>
<Ln>2</Ln>
<Item_Number>13</Item_Number>
<Producer_Address>Address2:</Producer_Address>
</detail_values>
<footer>
<Total_Plts_Lbl>Total2</Total_Plts_Lbl>
<Total_Invoice>0.00</Total_Invoice>
</footer>
</subreport>
</report>

=====End of XML file=====
Nov 12 '05 #1
1 2098
ALI,

You have to do most of the work yourself here. If you have an XML Schema
in XSD format for your format, then you can generate a set of classes to
read in and then check the properties on these classes. The .NET
Framework SDK (and hence Visual Studio) ships with a tool XSD.exe to
turn schemas into classes. Microsoft also released a newer tool on GDN
[0] if you're running into problems with xsd.exe.

If you don't have a schema, then you can infer one with xsd.exe or the
schema inference tool on GDN [1].

You can find samples on the XmlSerializer on TopXML [2].

After you deserialized the XML document, you can write code like:

foreach( SubreportType sub in report.subreport )
{
using( FileStream fs = new FileStream( sub.heading.Ship_Via, ... ) )
{
// write your file content here
}
}

HTH,
Christoph Schittko
MS MVP XML
http://weblogs.asp.net/cschittko
[0] http://apps.gotdotnet.com/xmltools/xsdobjgen/
[1] http://apps.gotdotnet.com/xmltools/xsdinference/
[2] http://www.topxml.com/xmlserializer/default.asp
-----Original Message-----
From: ALI-R [mailto:ne****@microsoft.com]
Posted At: Thursday, December 16, 2004 5:04 PM
Posted To: microsoft.public.dotnet.xml
Conversation: xml generator
Subject: xml generator

Hi All,

I have an xml file with the structure below.I'd like to create dynamic
number of xml files from this file based on <subreport> elements.each XML file contains
subreport element only .for instance if there are 4 <subreport> elements ,I'd like to create 4 different xml files and I want them to be named
based
on <Ship_Via> child value in each <subreport> element.

Is there somebody who can give me an idea?
thanks for your help.
ALI
====XML file====
<?xml version="1.0"?>
<report>
<subreport>
<heading>
<Sales_Order_Lbl>Sales Order1</Sales_Order_Lbl>
<Ship_Via>10-TR</Ship_Via>
</heading>
<detail_values>
<Ln>2</Ln>
<Item_Number>12</Item_Number>
<Producer_Address>Address1:</Producer_Address>
</detail_values>
<footer>
<Total_Plts_Lbl>Total2</Total_Plts_Lbl>
<Total_Invoice>0.00</Total_Invoice>
</footer>
</subreport>
<subreport>
<heading>
<Sales_Order_Lbl>Sales Order2</Sales_Order_Lbl>
<Ship_Via>11-TR</Ship_Via>
</heading>
<detail_values>
<Ln>2</Ln>
<Item_Number>13</Item_Number>
<Producer_Address>Address2:</Producer_Address>
</detail_values>
<footer>
<Total_Plts_Lbl>Total2</Total_Plts_Lbl>
<Total_Invoice>0.00</Total_Invoice>
</footer>
</subreport>
</report>

=====End of XML file=====

Nov 12 '05 #2

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

Similar topics

9
by: Francis Avila | last post by:
A little annoyed one day that I couldn't use the statefulness of generators as "resumable functions", I came across Hettinger's PEP 288 (http://www.python.org/peps/pep-0288.html, still listed as...
17
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next...
13
by: Emmanuel | last post by:
Hi, I run across this problem, and couldn't find any solution (python 2.2.2) : Code : =========== from __future__ import generators >>> class titi:
4
by: Wai Yip Tung | last post by:
I'm attempting to turn some process than uses callback to return result into a more user friendly generator. I'm hitting some road block so any pointer would be appriciated. Let say there is an...
45
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
12
by: Thomas Lotze | last post by:
Hi, I'm trying to figure out what is the most pythonic way to interact with a generator. The task I'm trying to accomplish is writing a PDF tokenizer, and I want to implement it as a Python...
5
by: Jerzy Karczmarczuk | last post by:
I thought that the following sequence gl=0 def gen(x): global gl gl=x yield x s=gen(1)
11
by: vbgunz | last post by:
I am afraid that this is the first time in which I would probably need something explained to me as if I were a little child. I am having a hard time getting this through my thick skull. What in...
20
by: Chris Withers | last post by:
Hi All, The following piece of code is giving me issues: from email.Charset import Charset,QP from email.MIMEText import MIMEText charset = Charset('utf-8') charset.body_encoding = QP msg =...
9
by: Kugutsumen | last post by:
I am relatively new the python language and I am afraid to be missing some clever construct or built-in way equivalent to my 'chunk' generator below. def chunk(size, items): """generate N items...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.