473,396 Members | 1,892 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.

how to create xml files out of an xml file based on an element

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 16 '05 #1
2 1043
Something like:

XmlDocument sourceDoc = new XmlDocument();
sourceDoc.Load(sourceFile);
#if GUARANTEED_ONLY_SUBREPORT_NODES_PRESENT_UNDER_ROOT
XmlNodeList subreportNodes = sourceDoc.DocumentElement.ChildNodes;
#else
XmlNodeList subreportNodes =
sourceDoc.DocumentElement.SelectNodes("subreport") ;
#endif
foreach (XmlNode subreportNode in subreportNodes)
{
XmlTextWriter xout = new XmlTextWriter
(string.Concat(OUTPUT_PATH,
subreportNode.SelectSingleNode("heading/Ship_Via").InnerText, ".xml",
Encoding.UTF8);
xout.Formatting = Formatting.Indented;
xout.WriteStartDocument(true);
subreportNode.WriteTo(xout);
xout.Close();
}

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"ALI-R" <ne****@microsoft.com> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl...
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 16 '05 #2
thank you very much indeed ,it is exactly what I want.

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:I%****************@news2.e.nsc.no...
Something like:

XmlDocument sourceDoc = new XmlDocument();
sourceDoc.Load(sourceFile);
#if GUARANTEED_ONLY_SUBREPORT_NODES_PRESENT_UNDER_ROOT
XmlNodeList subreportNodes = sourceDoc.DocumentElement.ChildNodes;
#else
XmlNodeList subreportNodes =
sourceDoc.DocumentElement.SelectNodes("subreport") ;
#endif
foreach (XmlNode subreportNode in subreportNodes)
{
XmlTextWriter xout = new XmlTextWriter
(string.Concat(OUTPUT_PATH,
subreportNode.SelectSingleNode("heading/Ship_Via").InnerText, ".xml",
Encoding.UTF8);
xout.Formatting = Formatting.Indented;
xout.WriteStartDocument(true);
subreportNode.WriteTo(xout);
xout.Close();
}

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"ALI-R" <ne****@microsoft.com> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl...
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 16 '05 #3

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

Similar topics

1
by: Donald Firesmith | last post by:
We are converting the OPEN Process Framework Repository (www.donald-firesmith.com) of over 1,100 free open source reusable process components for building development methods for...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
0
by: Chris Powell | last post by:
I am using Excel/Access 2000 and have two large Excel files (25,000 rows each) that I wish to create linked tables in Access rather than importing into Access. The two source Excel files change...
3
by: Dhananjayan | last post by:
Hi, I have a java webservice running on Axis, Iam able to create a java client to invoke the webservice and obtain the result. But iam not able to invoke the service from .Net client.. Here are...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
4
by: keithb | last post by:
ASP.NET Web Site Administration Tool sets access rules by folder, not by individual file. What would cause some files in a folder to be hidden and some to be displayed when...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
13
by: Bill Nguyen | last post by:
Is it possible to create your won XSD to use with .NET based on an XML content? For example the one below: <?xml version="1.0"?> <pcats:FuelsDoc...
11
by: sakhawn | last post by:
Hi, I have two files to merge using Java based on a similar text identifier: File 1: <ListRecords> <record> <header> ...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.