|
Copy the content of XSLT file into MSWORD and print it.
A DATAPOST COMPUTER CENTRE
(K.V Prajapati)
|
|
|
|
|
Thanks, but it not solve my solution.
|
|
|
|
|
I orginally posted this in the C# forum as I did not notice there was a xml forum...
I am trying to read an xml file into a dataset and have been met with nothing but problems.
The xml file is in the following format:
<?xml version="1.0"?><br />
<Catalog xmlns:dt="dt"><br />
<Rec><br />
<ITEM dt:dt="string"></ITEM><br />
<QTY dt:dt="string">1</QTY><br />
<SUB dt:dt="string"></SUB><br />
<CATALOG dt:dt="string">ABC123</CATALOG><br />
</Rec><br />
</Catalog>
I have tried this code in C#:
<br />
Dataset ds = new DataSet("Test");<br />
ds.ReadXML(OFD.FileName);<br />
When I set a breakpoint just after this code and examine ds, all have is a table called "Rec" and one column called "Rec_Id", clearly this is not what I want!!
Someone else has tried this and gets finds that ds has changed from "Test" to "Catalog", which is believed to have been picked up from the xml file. Expanding the Tables node reveals have 5 tables:
[0] Rec
[1] ITEM
[2] QTY
[3] SUB
[4] CATALOG
I think this can be done by specifing a schema, but I do not know how you do this whilst reading into a dataset nor do I know enough about schemas to know what to specify where!!
If I remove the dt:dt="String" datatypes then everything is fine. I do not want to manually do this so if this is the only way then how can I do it programatically? I need an automated solution.
Can anyone help?
Thanks
|
|
|
|
|
XSLT would be overkill for this.. maybe just iterate over everything and delete all dt:dt attributes?
|
|
|
|
|
I need to represent hierarchy of people who work under over persons I did it next way:
<?xml version="1.0" encoding="utf-8"?>
<person>
<name>Al</name>
<title>God</title>
<employees>
<person>
<name>Bart</name>
<title>Human</title>
<employees></employees>
</person>
<person>
<name>Lisa</name>
<title>Woman</title>
<employees></employees>
</person>
<person>
<name>Lionardo</name>
<title>Father</title>
<employees>
<person>
<name>Jim</name>
<title>Son</title>
<employees>
<person>
<name>Jim 2nd</name>
<title>Sub son</title>
<employees></employees>
</person>
</employees>
</person>
</employees>
</person>
</employees>
</person>
Is that right way to do that?
any help will appreciated!
|
|
|
|
|
Konstantin Yazvinski wrote: Is that right way to do that?
It's valid XML so if that is your requirement then yes it's right.
Or
The "right" way is dependent on your requirements. There could be many potential problems with the circular dependencies of person and employees. Well Formed XML has no problem with that but other things you might require could. Things like an ORM tool, Database Scheme or Serialization framework.
|
|
|
|
|
hi all,
i have to make a sample code using XmlDocument to select an XmlElement in this doc here is my file
<Root>
<node title="john">
</node>
<node title="Sam">
<node title="Charle">
<node title="jim"></node>
</node>
</node>
<node title="Sandra">
<node title="Amy"></node>
</node>
</Root>
and here is the method i wanna make
private static XmlElement findElement(string AttributeValue)
{
XmlDocument familyXml = new XmlDocument();
familyXml.Load("family.xml");
return siteMapXml.GetElementById(AttributeValue);// AttributeValue can be john, or jim ...
}
the problem that this method work only with ID attribute i notice wich supose that the ID is unique, how to select and XmlElement
without using an xPath because i don't know the deep of my xml tree.
thank you for help
|
|
|
|
|
I want to create one tool which will genereate the xslt...
The input will be an xml file and xslt will be generated to transofrm that xml to another....
Do anybody have any idea/code snippet/link to share?
Any help will be appreciated...
|
|
|
|
|
Any help on this one would be appreciated as it is doing my head in
As you will see by the "Current Output" I am generating unwanted translation tags containing the substring character generated in one of my for-each loops as it loops over my "Sample input"
I have a habit of getting this stuff inside out and back to front and am pretty sure the solution is staring me in the face in such an "obvious" fashion that I can't see it
The code I currently have
-----------------------------
<pre><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" indent="yes"/>
<!-- declaring 2 variables to hold "from" and "to" values -->
<xsl:variable name="from_what" select="Dictionary/@from"/>
<xsl:variable name="to_what" select="Dictionary/@to"/>
<xsl:template match="/">
<!-- hard coded task2.xsd reference -->
<Dictionary xsi:noNamespaceSchemaLocation="something.xsd" from="{$from_what}" to="{$to_what}">
<!-- outer loop to get a sorted search list -->
<xsl:for-each select="//dictionaryEntry">
<xsl:sort select="search"/>
<xsl:element name="translation">
<!-- substring the search string down to its
first character for the "initial" attribute-->
<xsl:attribute name="initial">
<xsl:value-of select="substring(search,1,1)"/>
</xsl:attribute>
<xsl:for-each select="search[not(.=preceding::search)]">
<xsl:element name="search">
<xsl:value-of select="."/>
</xsl:element>
<xsl:variable name="this_search" select="."/>
<xsl:for-each select="//dictionaryEntry[search=$this_search]">
<xsl:for-each select="replace">
<xsl:element name="replace">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</Dictionary>
</xsl:template>
</xsl:stylesheet>
</pre>
Current Output
-------------------------
<?xml version="1.0" encoding="utf-8"?>
<Dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="something.xsd" from="nl" to="es">
<translation initial="A">
<search>A Clockwork Orange</search>
<replace>La naranja mecánica</replace>
</translation>
<translation initial="A">
<search>Ab Urbe Condita</search>
<replace>Ab Urbe condita libri</replace>
<replace>Ab urbe condita</replace>
</translation>
<translation initial="A"/>
<translation initial="A">
<search>Ab Urbe Condita jaartelling</search>
<replace>Ab urbe condita</replace>
</translation>
<translation initial="B">
<search>Batman and Robin</search>
<replace>Batman y Robin</replace>
</translation>
</Dictionary>
Sample Input
---------------------
<?xml version="1.0" encoding="UTF-8"?>
<Dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="something.xsd"
from="nl"
to="es">
<dictionaryEntry>
<search>A Clockwork Orange</search>
<replace>La naranja mecánica</replace>
</dictionaryEntry>
<dictionaryEntry>
<search>Ab Urbe Condita</search>
<replace>Ab Urbe condita libri</replace>
</dictionaryEntry>
<dictionaryEntry>
<search>Ab Urbe Condita</search>
<replace>Ab urbe condita</replace>
</dictionaryEntry>
<dictionaryEntry>
<search>Ab Urbe Condita jaartelling</search>
<replace>Ab urbe condita</replace>
</dictionaryEntry>
<dictionaryEntry>
<search>Batman and Robin</search>
<replace>Batman y Robin</replace>
</dictionaryEntry>
</Dictionary>
|
|
|
|
|
hi craig,
i was wondering if you've already solved this problem? cause i too have another problem similar to this one but only has something similar with your line:
<xsl:for-each select="search[not(.=preceding::search)]">
i understand that you'll get like in your current output this line:
<translation initial="A" />
simply, how did you solve yours? (if you have solved it). i would appreciate it if you can post it. please and thanks!
modified on Sunday, April 25, 2010 12:33 AM
|
|
|
|
|
Any help on this one would be appreciated as it is doing my head in
As you will see by the "Current Output" I am generating unwanted translation tags containing the substring character generated in one of my for-each loops as it loops over my "Sample input"
I have a habit of getting this stuff inside out and back to front and am pretty sure the solution is staring me in the face in such an "obvious" fashion that I can't see it
The code I currently have
-----------------------------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" indent="yes">
<xsl:variable name="from_what" select="Dictionary/@from">
<xsl:variable name="to_what" select="Dictionary/@to">
<xsl:template match="/">
<dictionary xsi:nonamespaceschemalocation="something.xsd" from="{$from_what}" to="{$to_what}">
<xsl:for-each select="//dictionaryEntry">
<xsl:sort select="search">
<xsl:element name="translation">
<xsl:attribute name="initial">
<xsl:value-of select="substring(search,1,1)">
<xsl:for-each select="search[not(.=preceding::search)]">
<xsl:element name="search">
<xsl:value-of select=".">
<xsl:variable name="this_search" select=".">
<xsl:for-each select="//dictionaryEntry[search=$this_search]">
<xsl:for-each select="replace">
<xsl:element name="replace">
<xsl:value-of select=".">
Current Output
-------------------------
<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="something.xsd" from="nl" to="es">
<translation initial="A"> <search>A Clockwork Orange
<replace>La naranja mecánica
<translation initial="A"> <search>Ab Urbe Condita
<replace>Ab Urbe condita libri
<replace>Ab urbe condita
<translation initial="A"> <translation initial="A"> <search>Ab Urbe Condita jaartelling
<replace>Ab urbe condita
<translation initial="B"> <search>Batman and Robin
<replace>Batman y Robin
Sample Input
---------------------
<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
="" xsi:nonamespaceschemalocation="something.xsd" from="nl" to="es">
<dictionaryentry>
<search>A Clockwork Orange
<replace>La naranja mecánica
<dictionaryentry>
<search>Ab Urbe Condita
<replace>Ab Urbe condita libri
<dictionaryentry>
<search>Ab Urbe Condita
<replace>Ab urbe condita
<dictionaryentry>
<search>Ab Urbe Condita jaartelling
<replace>Ab urbe condita
<dictionaryentry>
<search>Batman and Robin
<replace>Batman y Robin
|
|
|
|
|
Hi Experts,
My Xml format is :
<Sis>
<Student>
<StudentID>1</StudentID>
<AcademicDetails>2008-2009</AcademicDetails>
<PersonalDetails>
<FirstName>Vijay</FirstName>
<MiddleName>Laxmanrao</MiddleName>
<LastName>Jadhav</LastName>
</PersonalDetails>
</Student>
</Sis>
I have seen lot of Xml's with Version information ie <? xml version="1.0" ?>.
My question is that what is a cause that my Xml didn't show version and other information.
My Sample code behind for creating Xml is :
#region Create Student Xml String
private string sCreateStudentXml()
{
try
{
Consumer.Sis studentDS = new Consumer.Sis();
Sis.StudentRow student_row = studentDS.Student.NewStudentRow();
student_row.StudentID = 1;
student_row.AcademicDetails = "2008-2009";
studentDS.Student.AddStudentRow(student_row);
Sis.PersonalDetailsRow sub_StudentPersonalDetails_row = studentDS.PersonalDetails.NewPersonalDetailsRow();
sub_StudentPersonalDetails_row.FirstName = "Vijay";
sub_StudentPersonalDetails_row.MiddleName = "Laxmanrao";
sub_StudentPersonalDetails_row.LastName = "Jadhav";
sub_StudentPersonalDetails_row.StudentRow = student_row;
studentDS.PersonalDetails.AddPersonalDetailsRow(sub_StudentPersonalDetails_row);
studentDS.AcceptChanges();
System.IO.StringWriter writer = new System.IO.StringWriter();
studentDS.WriteXml(writer, System.Data.XmlWriteMode.WriteSchema);
return writer.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
And my Xsd is :
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML Studio - 30 Day Trial Edition (http:
<xsd:schema id="Sis" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="StudentPersonalDetails">
<xsd:sequence>
<xsd:element name="FirstName" type="xsd:string" />
<xsd:element name="MiddleName" type="xsd:string" />
<xsd:element name="LastName" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="StudentType">
<xsd:sequence>
<xsd:element name="StudentID" type="xsd:int" />
<xsd:element name="AcademicDetails" type="xsd:string" />
<xsd:element name="PersonalDetails" type="StudentPersonalDetails" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ParentPersonalDetails">
<xsd:sequence>
<xsd:element name="FirstName" type="xsd:string" />
<xsd:element name="MiddleName" type="xsd:string" />
<xsd:element name="LastName" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ParentType">
<xsd:sequence>
<xsd:element name="ParentID" type="xsd:int" />
<xsd:element name="ParentPersonalDetails" type="ParentPersonalDetails" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Sis">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Student" type="StudentType" />
<xsd:element name="Parent" type="ParentType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Please help! If anyone know please reply.
Note : I have created above Xml against Xsd.
Thanks.
|
|
|
|
|
Why don't you just use it as it is ? Is it causing you problems ?!
Sincerely Samer Abu Rabie
Imagination is more important than knowledge !
|
|
|
|
|
Hi Samer,
Thanks for reply.
Because the XML declaration like : xmlns:xs="http://www.w3.org/2001/XMLSchema".
I am going to use later. The purpose is to identify, Xml based on Xsd.
Any solution ?
Vijay Jadhav.
|
|
|
|
|
You can use XmlWriter with XmlWriterSettings :
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = false;
settings.Indent = true;
XmlWriter xmlWriter = xmlWriter = XmlWriter.Create(
@"c:\temp\temp.xml", settings);
studentDS.WriteXml(xmlWriter);
xmlWriter.Close();
"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Tuesday, May 19, 2009 12:27 PM
|
|
|
|
|
Hi,
Thanks for your snippet.
Vijay Jadhav.
|
|
|
|
|
Hi all,
We have done it. Please view the following code snippet :
#region Create Student Xml String
/* Create Student Xml File */
private string sCreateStudentXml()
{
try
{
Consumer.Sis studentDS = new Consumer.Sis();
Sis.StudentRow student_row = studentDS.Student.NewStudentRow();
student_row.StudentID = 1;
student_row.AcademicDetails = "2008-2009";
studentDS.Student.AddStudentRow(student_row);
Sis.PersonalDetailsRow sub_StudentPersonalDetails_row = studentDS.PersonalDetails.NewPersonalDetailsRow();
sub_StudentPersonalDetails_row.FirstName = "Vijay";
sub_StudentPersonalDetails_row.MiddleName = "Laxmanrao";
sub_StudentPersonalDetails_row.LastName = "Jadhav";
sub_StudentPersonalDetails_row.StudentRow = student_row;
studentDS.PersonalDetails.AddPersonalDetailsRow(sub_StudentPersonalDetails_row);
// Accept the changes
studentDS.AcceptChanges();
System.IO.StringWriter writer = new System.IO.StringWriter();
studentDS.WriteXml(writer, System.Data.XmlWriteMode.IgnoreSchema);
XmlDocument doc = new XmlDocument();
doc.LoadXml(writer.ToString());
XmlNode root = doc.DocumentElement;
XmlAttribute att = doc.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
att.Value = "Sis.xsd";
root.Attributes.Append(att);
writer = new System.IO.StringWriter();
doc.Save(writer);
string sXML = writer.ToString();
sXML = sXML.Replace("utf-16", "utf-8");
return sXML.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
Thanks all for being with me!
Vijay Jadhav.
|
|
|
|
|
Hi Experts,
My Web Service have set of Xsd's. Like V1.xsd, V2.xsd, V3.xsd. From client side, client will send V1.xml based on V1.xsd in web service or V2.xml based on V2.xsd or V3.xml based on V3.xsd How will decide which Xml passed from client side to Xsd present in Web Service.
eg : My Sample Xml from Client1 is :
<Sis>
<Student>
<StudentID>1</StudentID>
<AcademicDetails>2008-2009</AcademicDetails>
<PersonalDetails>
<FirstName>Vijay</FirstName>
<MiddleName>Laxmanrao</MiddleName>
<LastName>Jadhav</LastName>
</PersonalDetails>
</Student>
</Sis>
How to determine Xsd for this in Web service ? Please help asap.
Note : I am using C#.Net (. Net FW 3.5) .
Thanks.
Mr. Vijay Jadhav.
modified on Monday, May 18, 2009 7:00 AM
|
|
|
|
|
Hi all
How do i delete a temporary html file if i store a xml file in
C:\temp
using C#
or my xml file is: testing.xml
How do i delete it ?
Thank You
|
|
|
|
|
hi, how do i parse out the value "system.web.ui.design.silverlightcontrols.collectioneditorbase" from below?
<member name="T:System.Web.UI.Design.SilverlightControls.CollectionEditorBase">
<summary>
Provides a utility class for Visual Studio property window behavior when editing media chapters.
</summary>
</member>
I tried using reader.Name, in which case reader is an instance of XMLTextReader class, but it gets only "member" string instead of the value after "=".
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
{
if (reader.Name == "members")
{
sw.Write(reader.Name);
sw.Write("\r\n");
}
break;
}
case XmlNodeType.Text: //Display the text in each element.
sw.Write(reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
sw.Write(reader.Name);
sw.Write("\r\n");
break;
}
}
|
|
|
|
|
I suggest you use www.w3schools.com and study the appropriate XML tutorials
|
|
|
|
|
I am trying to parse the below xml file
<myStuff>
<my Name>Tom Brown</myName>
<my Telephone>123456789</myTelephone>
<my Email>sample@testmail.com</myEmail>
<my Age>22</myAge>
<my Age>32</myAge>
<my Sex>M</mySex>
</myStuff>
with following code.
using (StreamWriter sw = new StreamWriter("result.txt", true))
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
sw.Write("<" + reader.Name.ToString());
sw.Write(">");
break;
case XmlNodeType.Text: //Display the text in each element.
sw.Write(reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
sw.Write("</" + reader.Name);
sw.Write(">");
break;
}
}
but it throws an exception because the Node name contains whitespace
can anyone help me fix this issue?
->the exception message is below.
System.Xml.XmlException was unhandled
Message="'>' is an unexpected token. The expected token is '='. Line 2, position 11."
Source="System.Xml"
LineNumber=2
LinePosition=11
SourceUri="file:///C:/Users/mirapark/Documents/Visual Studio 2008/Projects/simpleXMLparser/SimpleXMLParser/bin/Debug/sampleXML.xml"
StackTrace:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at WindowsFormsApplication1.Form1.xmlParse() in C:\Users\mirapark\Documents\Visual Studio 2008\Projects\IntellisenseFileTesting\IntellisenseFileTesting\Form1.cs:line 85
at WindowsFormsApplication1.Form1.button1_Click_1(Object sender, EventArgs e) in C:\Users\mirapark\Documents\Visual Studio 2008\Projects\IntellisenseFileTesting\IntellisenseFileTesting\Form1.cs:line 35
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at WindowsFormsApplication1.Program.Main() in C:\Users\mirapark\Documents\Visual Studio 2008\Projects\IntellisenseFileTesting\IntellisenseFileTesting\Program.cs:line 21
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
|
|
|
|
|
Simply as you said it holds white spaces in the tag ! You can't have white spaces in the tag UNLESS you will be adding an attribute ... the tag name should always be one word whitespace-less !
Sincerely Samer Abu Rabie
Imagination is more important than knowledge !
|
|
|
|
|
The code isn't at fault, the XML is not properly formed.
|
|
|
|
|
I want to make changes to and xml document using the xmltextreader and xmltextwriter. The changes to write back to the xml document are stored in a datatable. I think I want to read each line using the xmltextreader using a while loop. Within the loop I want to write it out using the xmltextwriter. What is the code syntax I would use to read a line of data in the xml document and write it to the xml document?
|
|
|
|