|
Console application:
<br />
Option Strict Off<br />
Imports System.IO<br />
Imports System.Xml<br />
Module Module1<br />
<br />
Sub Main()<br />
Try<br />
Dim iStartPositions As Integer() = {0, 4, 5, 14}<br />
Dim sFixedWidthText As String = GetFileContents("C:\FixedWidthText.txt")<br />
Dim sw As New StringWriter<br />
Dim writer As New XmlTextWriter(sw)<br />
writer.WriteStartElement("Rows")<br />
Dim sRows As String() = sFixedWidthText.Split(vbCrLf)<br />
Dim iRow, iColumn As Integer<br />
Dim sRowText As String<br />
Dim al As ArrayList<br />
For iRow = 0 To sRows.Length - 1<br />
writer.WriteStartElement("Row")<br />
sRowText = sRows(iRow)<br />
al = GetDelimitedTextArray(sRowText, iStartPositions)<br />
For iColumn = 0 To al.Count - 1<br />
writer.WriteStartElement("Column" & iColumn)<br />
writer.WriteString(al(iColumn))<br />
writer.WriteEndElement()<br />
Next<br />
writer.WriteEndElement()<br />
Next<br />
writer.WriteEndElement()<br />
SaveTextToFile(sw.ToString, "C:\FixedWidthText.xml")<br />
Console.WriteLine("File saved")<br />
Console.ReadLine()<br />
Catch ex As Exception<br />
Console.WriteLine(ex.ToString)<br />
Console.ReadLine()<br />
End Try<br />
End Sub<br />
Public Function GetDelimitedTextArray(ByVal sRowText As String, ByVal iStartPositions As Integer()) As ArrayList<br />
Dim al As New ArrayList<br />
Dim i As Integer<br />
Dim sColumnText As String<br />
For i = 0 To iStartPositions.Length - 1<br />
If i = iStartPositions.Length - 1 Then<br />
sColumnText = sRowText.Substring(iStartPositions(i))<br />
Else<br />
sColumnText = sRowText.Substring(iStartPositions(i), iStartPositions(i + 1) - iStartPositions(i))<br />
End If<br />
al.Add(sColumnText)<br />
Next<br />
Return al<br />
End Function<br />
Public Function GetFileContents(ByVal FullPath As String) As String<br />
Dim sContents As String<br />
Dim oReader As New StreamReader(FullPath)<br />
sContents = oReader.ReadToEnd()<br />
oReader.Close()<br />
Return sContents<br />
End Function<br />
Public Sub SaveTextToFile(ByVal sData As String, ByVal FullPath As String)<br />
Dim oWriter As StreamWriter<br />
oWriter = New StreamWriter(FullPath)<br />
oWriter.Write(sData)<br />
oWriter.Close()<br />
End Sub<br />
<br />
End Module<br />
<br />
<br />
Contents of test file:
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
Hope this helps. Will need to improve exception handling and data checks (i.e. If row text is less than expected etc). Also best to encapsulate functionality as a seperate utility class with overloaded functions i.e. to get xml as string, save as file or return xmldom document etc.
Jim
|
|
|
|
|
This is probably an easy one...
I have implemented a CHOOSE function in an XSLT transformation as follows:
<code>
<!-- ====[CONTENT]================================ -->
<xsl:variable name="selBoxHeight" select="count(./Content/content_name)"></xsl:variable>
<TR><TD>
<DIV><xsl:value-of select="$selBoxHeight" /></DIV>
<!-- HTML ListBox -->
<SELECT>
<xsl:attribute name="class">menuoptionselectboxes</xsl:attribute>
<!-- Set Select Box height -->
<xsl:choose>
<xsl:when test="$selBoxHeight <= 7">
<xsl:attribute name="Size"><xsl:value-of select="$selBoxHeight"></xsl:value-of></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="Size"><xsl:value-of select="7"></xsl:value-of></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<code>
I'm having a problem with the evaluation of :
test="$selBoxHeight <=7" where the transformation fails, returning the following error:
System.Xml.XmlException: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 51
I have verified that this sort of comparison can be performed, see for example: O'Reilly's XML.Com.
Even so , I have this niggling error.
Has anyone got help on the matter??
Thanks in advance
Drikus
|
|
|
|
|
test="$selBoxHeight <=7"
|
|
|
|
|
|
Hello!
I program with Configuration Management application block
I need to use configuration files at more then two levels:
<Section>
<SubSection>
<SubSection>
<Element>
</SubSection>
</SubSection>
How can I do it using CMAB? ConfigurationSectionHandler?
</Section>
|
|
|
|
|
I'm just at the early stages of learning XML, which no specific target at the moment. When I'm learning new technologies, one tactic I like to employ is to take an old application of mine and "upgrade" to use the new technology. That way I'm starting off in familiar territory and doing incremental learning. That's my theory, anyway.
So anyway, I have my somewhat aging shareware app which uses MFC's CDocument & CArchive for database storage. It looks to me to be an ideal application for conversion to XML storage.
My question: before I get too far down the wrong path, is there an easy way to initially port my MFC code to use XML storage instead of CArchive, or should I just use one of the sample classes posted here and rewrite all of my serialization code?
I'd have hoped MS would have updated MFC to include a "CXMLArchive" class to drop in place, but apparently that was a bit too much to hope for. :-/
|
|
|
|
|
I am writing a facility in vb6 to export a number of records to an xml file that will then be sent to an organisation for processing. In the example of how they want the xml document to look they use ...
<?xml version="1.0" encoding="UTF-16"?>
However, when I go to view my document in MS Internet Explorer(6.0), I receive the following error ...
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
Switch from current encoding to specified encoding not supported. Error processing resource 'file:///G:/Temp/104749-031001.xml'. Line 1, Position 40
Removing the encoding let's me view the document correctly, so is the UTF encoding absolutely necessary and does it affect the document if it's used on another machine or os?
Matthew
Live to ride. Ride to live.
|
|
|
|
|
The encoding attribute in the XML processing instruction is to indicate the encoding of the document, so it is likely that the document you are creating is not in that encoding hence the error. To check this look at the xml file you are creating in a hex editor, in utf-16 there are (at least) two bytes per character...
|
|
|
|
|
|
Hello,
Greetings!
I'm trying to make a sample app in VC++ 6.0 to prepare and send a SOAP message to a webserver. I'm using gSOAP Toolkit 2.3 (http://www.cs.fsu.edu/~engelen/soap.html[^]) for the same at the client end, while I have "Windows 2000 Pro/Apache v1.3/PHP-4.3/NuSOAP.php" on the test server end. (Yeah, it is not a Win2K Server, but it is a Professional version of Win2K!)
Any idea about how to make and use the namespace file at the client end?
The documentation (UserGuide) is not quite helpful!! ... So if you have used a similar kind of setup, and can reply back, I would be grateful.
Thanks,
Rgds,
Nirav
---------------------------------------------------
* Don't wish it was easier; Wish you were better! *
---------------------------------------------------
|
|
|
|
|
Hi,
I got the solution with some trial and error...
Thanks anyway!
If anybody needs help on this, please let me know!
Thanks,
Rgds,
Nirav
---------------------------------------------------
* Don't wish it was easier; Wish you were better! *
---------------------------------------------------
|
|
|
|
|
I create dynamic xml document with dom.The xml seem
<record>
<a>fasfd</a>
<b>fdasfas</b>
<record>
or
<record>
<b>fasf</b>
<a>fdsfs</a>
</record>
or
<record>
<a>fds</a>
<a>fsfsfsfd</a>
<b>232432</b>
<a>werwrw</a>
<record>
how do i specify the order? the complexType must is: sequence or choice or all,but these don't apply my xml doc. Have there a way that don't need specify order?
linjie
|
|
|
|
|
Use a repeating choice ordering group, eg for you examples
<complexType>
<choice maxOccurs="unbounded">
<element name="a" type="string"/>
<element name="b" type="string"/>
</choice>
</complexType>
|
|
|
|
|
Thanks very muth,My problem has be solved.
linjie
|
|
|
|
|
1.I create a xml document with dom. I want specify a schema to the xml document? how do i do?
2.The xml document created by dom isn't a formated document,e.g
<record>sdafs</record><record>fsdfsdfa</record>..............
are there a way to format it for newline and indenting?
linjie
|
|
|
|
|
I hope this provides some clarity:
Create a schema for your example document (snippet), which I formatted as follows:
<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\...\record.xsd">
<record>sdafs</record>
<record>fsdfsdfa</record>
</ROOT>
The schema reference has been inserted as a noNamespaceSchemaLocation, in this example the XSD schema located somewhere on your local drive, eg c:\.
The schema, which I created with XMLSpy, may look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSPY v2004 rel. 2 U (http:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="ROOT">
<xs:complexType>
<xs:sequence>
<xs:element name="record">
<xs:complexType/>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Validating the XML document will now happen against the XSD schema. An XSLT transform may be applied to render it in a browser.
|
|
|
|
|
thanks,but how do i do it with dom? I has created a schema for the xml documnet, I used following code
pRootElement->setAttribute(CComBSTR("xmlns"),CComVariant("http://www.myweb.com/mySchema.xsd"))
but all node has a excrescent attribute,e.g
<?xml version="1.0"?>
<ROOT xmlns="http://www.myWeb.com/mySchema.xsd">
<record xmlns="">sdafs</record>
<record xmlns="">fsdfsdfa</record>
</ROOT>
linjie
|
|
|
|
|
Your problem seems to be with setAttribute or the use of CComBSTR.
Not too sure, but try these out:
setAttribute
CComBSTR
|
|
|
|
|
Hi, I'm new to xsl and am I'm just trying to pass an asp session variable into my xsl to include into a form that will be mixed with some xml data.
I've tried using both the addparameter and addobject methods (i.e. something like:
------------------------------------------------
XSL1.addParameter session("ID"), sessionID
-------------------------------------------------
and I can't get either one to work. There has to be something I'm missing here, but for the life of me I can't seem to figure out what it is.
My code is as follows....
-----------------------------------------------
'Load XML from file
Set XML1 = CreateObject("MSXML2.DOMDocument.3.0")
XML1.async = False
XML1.Loadxml availresponse
'Load XSL from file
Set XSL1 = CreateObject("MSXML2.DOMDocument.3.0")
XSL1.async = False
XSL1.Load server.MapPath("availrooms.xsl")
-----------------------------------------------
...then later in the script I do the transform with the following line:
-------------------------------------------------
<td> <%= XML1.transformNode(XSL1)%>
-------------------------------------------------
Any help would be greatly appreciated!
|
|
|
|
|
Another one,
Now the guy that was suppose to create an XSL for me, "fixed" my html to look like the print, which doesn't help me much....
How do I make the text fit the shape????
How do I change the font size?
How do I center the text in the shape?
I tried to understand the examples all the sites give, but nothing works.
Please, can you help?
Thanks,
Cgull
|
|
|
|
|
You stated in your last post that you don't know anything about XML, HTML (not necessarily related to XML, BTW), or VML. That would definitely be the first place to start. Pick up a good book or hop over the W3C and start reading specs.
Even though you've stated your problem in the most vague way immaginable, you haven't stated what is wrong exactly - most likely because you're not even sure where the problem lies. Without knowing something more, it is hard to help you with problems like this.
A development community such as this one can't - and isn't designed - to teach you everything. You should at least have some working knowledge of what you're getting into. If you don't understand anything about XML or VML, we can't necessarily teach you. There are articles on CP that can help, but developing a working knowledge is important before using the forums - they're for helping with a problem when people were stuck.
Even if you could tell us in technical terms what the problem is (and you didn't even give a code fragment or example - and don't post the whole file please), could you necessarily understand the answer? You'd best learn your subject matter to some degree first.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Wow, if words could kill...
I did try to add example, but it didn't go through.
I did go to W3C site, but the exapmles there didn't help me much.
When I'm trying to fit a text into a shape, whatever I do does not work.
If I try to change the font size, also does not work.
e.g.
<v:textpath style="v-rotate-letters: true; font-size: small" fitshape="true">
<v:textbox style="v-text-anchor: top">3086-UNKNOWN CHEQUE MATCHING
Whatever I did inside the textpath or the textbox, the text stayed the same.
No change of the font size, rotation, middle-center or any other attribute I tried.
|
|
|
|
|
Hello good people,
I'm tring to write something in VML for the first time.
The script I created looks great on Microsoft VML Generator, I saved it as HTML, and opened it with Explorer, and still looks great, but when I print it, the lines move and it's not so great anymore.
Have to say, I know nothing about XML, HTML or VML and I don't know what am I doing wrong.
I also tried to use some examples from the net, on the VML generator, and none of them work.
Why, why, why?
Please help,
Thanks,
Cgull
|
|
|
|
|
|
Hi,
i'm using VS.net 2003 with .NET Framework 1.1. I'd like to use signedXML in the Namespace System.Security.Cryptography.XML. But when i'm trying to include (with "using") the namespace in C#, the only namespace VS.net displays under System.Security.Cryptography is X509Certificates.
Where is the XML Namespace?
Can someone please help me and tell me how to solve this problem?
Thanks
Obi
|
|
|
|
|