Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Produce xsd file

Posted on 2013-02-05
5
Medium Priority
?
196 Views
Last Modified: 2013-02-19
Thanks to the answer I received here I was able to produce the xml file.
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_28015259.html

How do I control whether the top line says
<?xml version="1.0"?>  or <?xml version='1.0'?>  single or double quotes

How do I produce an xsd for the xml files I produce?

I'm writing a c# executable in visual studio 2008 .net framework 3.5.
0
Comment
Question by:AlHal2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 7

Accepted Solution

by:
tipsybroom earned 750 total points
ID: 38854381
0
 

Author Comment

by:AlHal2
ID: 38854445
I tried adding it just after I call the parsexml routine and get the message doc does not exist in the current context.

Not sure if it's relevant, but the xsd needs to be in a separate file.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Xml.Linq;
using System.Xml.XPath ;
namespace ILXSymbolMasterExtract
{
    public partial class Form1 : Form
    {
       
        string[] arrAttrBond = {
                                "sedol","curr","localId","issuShortDesc","exch","longIssuerName", "symbol",
                                "action","sectyType","cusip","issuLongDesc","localCode","dfltInd",
                                "mat","isin","sess","issuerName"
                           };
        string[] arrAttrInd = {
                                "sedol","curr","localId","issuShortDesc","exch","longIssuerName", "symbol",
                                "action","sectyType","cusip","issuLongDesc","localCode","dfltInd",
                                "isin","sess","issuerName","sicCode"
                           };

        string[] arrAttrTr = {
                                "sedol","issuerName","mat","symbol","sess","issuShortDesc","cusip",
                                "issuLongDesc","longIssuerName","sectyType","action","isin","exch","curr",
                           };

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {


                ParseXml(@"C:\\CAMCont\Input\\symbol_master.xml", @"C:\\CAMCont\Output\\symbol_master_bond.xml", "bond", "bnd", arrAttrBond);
                ParseXml(@"C:\\CAMCont\Input\\symbol_master.xml", @"C:\\CAMCont\Output\\symbol_master_ei.xml", "index", "ind", arrAttrInd);
                ParseXml(@"C:\\CAMCont\Input\\symbol_master.xml", @"C:\\CAMCont\Output\\symbol_master_treasury.xml", "treasury", "tr", arrAttrTr);

                //XmlDeclaration xmldecl;
                //xmldecl = doc.CreateXmlDeclaration("1.0", null, null);

                ////Add the new node to the document.
                //XmlElement root = doc.DocumentElement;
                //doc.InsertBefore(xmldecl, root);
               


                //Console.WriteLine("Display the modified XML...");
                //doc.Save(Console.Out);

           
            }
               
            catch (Exception ex)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(ex.Message);
            }
            Environment.Exit(0);
           
        }
       

        private void ParseXml(string fn, string fnout,string InstTypeMain,string InstTypeMinor,string[] AttributeInst)
        {

            using (Stream stream = File.OpenRead(fn))
            {
               
                XmlTextReader r = new XmlTextReader(stream);
                r.WhitespaceHandling = WhitespaceHandling.None;
                r.MoveToContent();

                using (XmlTextWriter w = new XmlTextWriter(fnout,null ))
                {
                    w.Formatting = Formatting.Indented;
                    w.Indentation = 3;
                    //w.IndentChar = '\t';
                    w.IndentChar = ' ';
                    w.WriteStartDocument();
                    w.WriteStartElement("data");

                    int intParsingState = 0;

                    // changed the loop structure to start at root (not really necessary) but also to be able to use "continue" to skip r.Read() after r.Skip()...
                    do
                    {
                        switch (r.NodeType)
                        {
                            case XmlNodeType.Element:

                                if (r.LocalName == InstTypeMain)
                                {
                                    intParsingState = 1;
                                }
                                else if (r.LocalName == InstTypeMinor)
                                {
                                    if (intParsingState > 0)
                                    {
                                        w.WriteStartElement("n");
                                        foreach (string a in AttributeInst)
                                        {
                                            w.WriteElementString(a, r.GetAttribute(a).ToString());
                                        }
                                        w.WriteEndElement();
                                    }

                                }
                                else
                                {
                                    // skip children of other elements on the same depth as the <bond> element
                                    if (r.Depth >= 1)
                                    {
                                        r.Skip();
                                        continue; // don't call r.Read() in this case...
                                    }

                                }
                               
                                break;
                            case XmlNodeType.EndElement:
                               
                                if (r.LocalName == InstTypeMain)
                                {
                                    intParsingState = 2; // break do-while
                                }

                                break;
                            default:
                                break;
                        }
                        if (intParsingState < 2 && !r.Read())
                            break;
                    } while (intParsingState < 2);
                    w.WriteEndElement();
                    w.WriteEndDocument();
                    w.Flush();
                    w.Close();
                }
                r.Close();
            }
        }
       
    }
}
0
 
LVL 4

Expert Comment

by:Srinivasulu Muppala
ID: 38858828
Do you want to produce XSD for xml data?
0
 

Author Comment

by:AlHal2
ID: 38864442
yes please.
0
 

Author Closing Comment

by:AlHal2
ID: 38904989
A step in the right direction.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question