|
Hi
I using xml schema to validate xml.
My xml is looking like this:
<some_name>
... some integer and string elements
<xmlData>
... random xml data, like : <a>asd</a><b>dsds</b>
</xmlData>
</some_name>
I have no problem with integer and string data, but I don't know to which type to set xmlData element.
xmlData can contain random xml which structure is unknown. I just want to know that xmlData element is presenting and have some elements
Any suggestions?
10x in advance.
|
|
|
|
|
I think the type is 'anyType'
Denevers
|
|
|
|
|
Hmm and how to use it?
I try this schema:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="MyID" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstElement" type="xs:string"/>
<xs:element name="XMLElement" type="xs:anyType" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
for this xml:
<Root>
<FirstElement>sdsdd</FirstElement>
<XMLElement>1</XMLElement>
</Root>
and it works whenever XMLElement is string or integer, but if I add an element in XMLElement, like here:
<Root>
<FirstElement>dsds</FirstElement>
<XMLElement><a>sdsd</a></XMLElement>
</Root>
an error appear - The 'a' element is not declared. An error occurred at , (3, 15)
|
|
|
|
|
Sorry about this.. I just answered from the top of my head, which ended up being empty.
you must use xs:any and provide a processContents instruction, lax = will try to apply a schema, but won't complain if it does not find any. processContent = "skip" will tell the validator to skip validation.
<xs:element name="MyContainer">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstElement" type="xs:string"/>
<xs:element name="XMLElement">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##any" processContents="lax"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
see http://www.w3schools.com/schema/el_any.asp for details
Denevers
-- modified at 8:27 Monday 3rd April, 2006
|
|
|
|
|
That's what I need.
xs:any + processContents="skip" do the job
Thank You
|
|
|
|
|
you are most welcomed.
cheers
Denevers
|
|
|
|
|
Hey,
I am looking for recommendations for an Xml Editor that can be supported in a WinForm. Free or Commercial.
Thanks in advance!
Bill
|
|
|
|
|
I am new to XML world. I want to know is there any downloadable utility software (Not MSXML parser) using which I can check the validity of XML document against a XSD file. Also I want to know how I can do the same validation using VB.Net code.
Regards,
Krishnaraj
|
|
|
|
|
|
Can I wrap IXMLDOMDocumentPtr in the smart pointer CComQIPtr ? If Yes, what is the IID of IXMLDOMDocumentPtr ?
Thanks ...
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
hi there,
i have a dataset which xml data is loaded, i have performed several operations can i rollback the change done toit set by step??.
thanks in advance
bharath.s
|
|
|
|
|
Since a dataset is involved, I guess you can create transactions to perform the operations. If one operation fails, you can roll back the transaction.
Hope this helps..
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
I am using XML and XSL to transform XML files into source code for different programming languages.
But in C literals are WRITTEN_UPPERCASE_WITH_UNDERSCORES while C# programmers like MixedCaseWithNoUnderscore.
It's easy to convert "Quick Brown Fox" to "QUICK_BROWN_FOX" and "QuickBrownFox", but how about "QuickBrownFox" to "QUICK_BROWN_FOX"?
Or the other way round, "QUICK_BROWN_FOX" to "QuickBrownFox"?
Thanks in advance
Andre
|
|
|
|
|
Hello, I am quite new on this site, so I do not know what kind of answers are expected.
I expect that you want to transform these in the XSL.
I have created, quickly and untestedly - two templates that you should be able to call that will do what you want. You call one of them with a parameter containing the string that you want transformed.
I hope this helps
Regards,
Ragulf Pickaxe
<!-- Global variables -->
<xsl:variable name="Upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="Lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="Marker" select="'**************************'"/>
<xsl:template name="c-lit-to-c-sharp-lit">
<xsl:param name="c-lit" select="''"/>
<xsl:if test="$c-lit!=''">
<xsl:value-of select="sustring($c-lit,1,1)"/>
<xsl:value-of select="translate(substring-before($c-lit,'_'),$Upper,$Lower)"/>
<xsl:call-template name="c-lit-to-c-sharp-lit">
<xsl:with-param name="c-lit" select="substring-after($c-lit)"/>
</xsl:call-temaplate>
</xsl:if>
</xsl:template>
<xsl:template name="c-sharp-lit-to-c-lit">
<xsl:param name="c-sharp-lit" select="''"/>
<xsl:if test="$c-sharp-lit!=''">
<xsl:variable name="marked-c-sharp-lit" select="translate($c-sharp-lit,$Upper,$Marker)"/>
<xsl:value-of select="sustring($c-sharp-lit,1,1)"/>
<xsl:value-of select="translate(substring-before($marked-c-sharp-lit,'*'),$Lower,$Upper)"/>
<xsl:call-template name="c-sharp-lit-to-c-lit">
<xsl:with-param name="c-sharp-lit" select="substring($c-sharp-lit,string-length(substring-before($marked-c-sharp-lit,'*')),1 div 0)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
|
|
|
|
|
Hey, I am creating an application, and need some help.
It uses an XML file to keep tabs on documents created with it, and when the user presses a button i want to update that document's status in the XML file to "Finished".
So far i have XML files similar to the following:
http://pastebin.com/600756[^]
I need to modify the <status> tag of a specific report based on its ID, how would i go about doing this?
I would appreciate any help you can give me
James
|
|
|
|
|
i am final year student doing a project in XML and just want solution to the querie posted by you
kindly respond
remya
|
|
|
|
|
Hi
I developed an application using VB.NET with VS 2005.
I add xml comments as needed to every method/class/members etc.
Now i want to create an help file based on this comments.
I found a convertion tool for C# (NDoc) but not for VB.NET.
I need a simple tool to create a MSDN like help file based on VB.NET xml coments.
Tnx
-- modified at 6:59 Sunday 12th March, 2006
|
|
|
|
|
Hi all,
I'm trying to read a file wuth C#. The file contains the following:
<?xml version="1.0" encoding="utf-8" ?>
<voice_config>
<voice_type>Microsoft Mary</voice_type>
<voice_volume>100</voice_volume>
<voice_rate>0</voice_rate>
</voice_config>
and the code to read is:
voice_reader.Read();
voice_reader.ReadStartElement("voice_config");
voice_reader.ReadStartElement("voice_type");
m_voice = voice_reader.ReadString();
voice_reader.ReadEndElement();
voice_reader.ReadStartElement("voice_volume");
m_volume = voice_reader.ReadContentAsInt();
voice_reader.ReadEndElement();
voice_reader.ReadStartElement("voice_rate");
m_rate = voice_reader.ReadContentAsInt();
voice_reader.ReadEndElement();
voice_reader.ReadEndElement();
I'm getting the following exception thrown:
Exception : Unexpected XML Declaration. The XML Declaration should be the first node in the document, and no whitespace characters are allowed to appear before it, Line 1 position 100
|
|
|
|
|
// You are not advancing through the document, Example:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace XmlRdr
{
class Program
{
static void Main(string[] args)
{
XmlReader voice_reader = null;
try
{
voice_reader = XmlReader.Create(@"C:\voice_config.xml");
while (voice_reader.Read())
{
if (voice_reader.NodeType == XmlNodeType.Element)
{
switch (voice_reader.Name)
{
case "voice_config":
break;
case "voice_type":
Console.WriteLine(voice_reader.ReadString());
break;
case "voice_volume":
Console.WriteLine(voice_reader.ReadString());
break;
case "voice_rate":
Console.WriteLine(voice_reader.ReadString());
break;
default:
break;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
if (voice_reader != null && voice_reader.ReadState != ReadState.Closed)
{
voice_reader.Close();
}
}
}
}
}
|
|
|
|
|
Got it now. Knew it would be simple.
|
|
|
|
|
Hi,
I'm designing a framework for an enterprise application.
I have done this earlier but I used to define model (properties, methods, events…) inside framework itself.
Programmer writes codes based on the model defined in framework, in other words interface that is created inside framework later implemented by the programmer.
Now I would like to isolate model definition from framework and define the model in a separate XML file so that framework will extract model definition from XML file dynamically.
How do I achieve this ?
Advance Thanks !
Regards,
aB
|
|
|
|
|
Using "Reflection" might be an option.
|
|
|
|
|
Hi to everybody,
I need some help to convert a XML DataSet to an Excel file. I actually using this code:
Private Sub TransformXML(ByVal xmlDoc As XmlDataDocument, _
ByVal strXSLPath As String, _
ByVal strSavePath As String)
Dim xt As New XslCompiledTransform
Dim tw As XmlTextWriter
tw = New XmlTextWriter(strSavePath, System.Text.Encoding.UTF8)
tw.Formatting = Formatting.Indented
tw.Indentation = 3
tw.WriteStartDocument()
xt.Load(My.Application.Info.DirectoryPath & strXSLPath)
xt.Transform(xmlDoc, Nothing, tw)
tw.Close()
End Sub
The XSLT follow here :
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns ="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" >
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns ="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:apply-templates/>
</Workbook>
</xsl:template>
<xsl:template match="/*">
<Worksheet>
<xsl:attribute name="ss:Name">
<xsl:value-of select="local-name(/*/*)"/>
</xsl:attribute>
<Table x:FullColumns="1" x:FullRows="1">
<Row>
<xsl:for-each select="*[position() = 1]/*">
<Cell>
<Data ss:Type="String">
<xsl:value-of select="local-name()"/>
</Data>
</Cell>
</xsl:for-each>
</Row>
<xsl:apply-templates/>
</Table>
</Worksheet>
</xsl:template>
<xsl:template match="/*/*">
<Row>
<xsl:apply-templates/>
</Row>
</xsl:template>
<xsl:template match="/*/*/*">
<Cell>
<Data ss:Type="String">
<xsl:value-of select="."/>
</Data>
</Cell>
</xsl:template>
</xsl:stylesheet>
The problem is that the XSLT must be generic because the DataSet it's always different. I would like to retrieve the datatype from the DataSet schema and create the Excel file properly. The XSLT attached perform only a simple transformation.
Can anyone help me with XSLT and kindly provide a better implementation?
Thanks in advance to anyone will replay
|
|
|
|
|
Dim ds4xmlcsv As New DataSet
Dim export As New ConvertXMLtoCSV
Dim f1 As File
Dim fullpath As String
Try
ds4xmlcsv.ReadXml(cc)
export.Export(ds4xmlcsv, True)
ds4xmlcsv.Clear()
If MsgBox("The Transfer is Complete", MsgBoxStyle.MsgBoxSetForeground.OKOnly, "Thank You") = MsgBoxResult.OK Then
btntrs2csv.Enabled = False
Exit Sub
End If
Catch errormsg As Exception
MsgBox(errormsg.Message + sessiontime.Now)
End Try
Public Function Export(ByVal ds As DataSet, ByVal exportcolumnheadings As Boolean) As String
'Dim ts11 As String
'ts11 = txtinputxmltext
'TextBox1.Text = ""
Dim ts As String
'Dim rep As String
Dim ts22 As String
ts22 = "XML2CSV.csv"
ts = Path.GetFileName(txtsavetext)
fname = txtsavetext.Replace(ts, ts22)
Dim header As String
Dim body As String
Dim record As String
Dim f As file
Dim ii As Integer
'Dim cc As String
'cc = "C:\bin\XMLInput.csv"
'f.CreateText(cc)
If f.Exists(fname) Then
f.Delete(fname)
End If
Dim writer As StreamWriter = New StreamWriter(fname)
If exportcolumnheadings Then
For Each col As DataColumn In ds.Tables(0).Columns
header = header & Chr(34) & col.ColumnName & Chr(34) & ","
Next
header = header.Substring(0, header.Length - 1)
writer.WriteLine(header)
writer.Close()
End If
For Each row As DataRow In ds.Tables(0).Rows
Dim arr() As Object = row.ItemArray()
For i As Integer = 0 To arr.Length - 1
If arr(i).ToString().IndexOf(",") > 0 Then
record = record & Chr(34) & arr(i).ToString() & Chr(34) & ","
Else
record = record & arr(i).ToString() & ","
'cc.Concat(header, record)
End If
Next
'If ii = 0 Then
' Dim writer2 As StreamWriter = New StreamWriter(cc, False)
' writer2.WriteLine(record)
' writer2.Close()
' ii = 1
'Else
Dim writer2 As StreamWriter = New StreamWriter(fname, True)
writer2.WriteLine(record)
writer2.Close()
'End If
body = body & record.Substring(0, record.Length - 1) & vbCrLf
record = ""
Next
If exportcolumnheadings Then
Return header & vbCrLf & body
'writer.WriteLine(header & vbCrLf & body)
'writer.Close()
Else
Return body
'writer.WriteLine(body)
End If
End Function
bharath.s
-- modified at 5:52 Friday 17th March, 2006
|
|
|
|
|
Thanks for your reply, but I want to convert my XML to XLS using XSLT.
Here an example of what I want to have!
http://support.microsoft.com/?kbid=319180
The code posted already work, I need only a better implementation of the stylesheet...
Thanks again
|
|
|
|