|
Without checking this out it may be because of the BSTR constructor you are using. BSTR's are unsigned short pointers, while you are passing in a const char* so a pointer cast is probably done (by the compiler) so two characters from your const char will be going into one character of the BSTR ie could be any character!! I suggest you try using CComBSTR, _bstr_t, or SysAllocString (and a matching free) to create your string to parse...
|
|
|
|
|
Thanks for your help. I finally found that my problem was a combination of two different problems.
1. Here was the real problem: I was loading (as binary) a Unicode file that has a BOM (byte-order mark) at the front of the file. Then I passed the text to loadXML. Apparently, loadXML can't handle Unicode special characters. I consider this a bug in loadXML.
2. In order to test loadXML, I was creating a BSTR like this:
BSTR( "< ParticleSystem />" );
Like you said, the constructor was not converting the string to a Unicode string as I expected it to do. loadXML was able to parse this:
BSTR( L"< ParticleSystem />" );
|
|
|
|
|
If it's any consolation, I've hit that first problem too. My solution was to provide an IStream implementation that ate the BOM from it's input if present; it used memory mapped files so didn't ever call ReadFile...
Steve S
|
|
|
|
|
|
Michael Dunn wrote:
Jambolo wrote:
BSTR( L"< ParticleSystem />" );
That is still not correct, you need to make a real BSTR or use a wrapper class like _bstr_t
Well, it worked just fine, so I'm not convinced. Regardless, I am using CComBSTR for the real code, but I will keep that in mind for next time.
|
|
|
|
|
Hi,
I've got an XML file which I want to read in vb.NET.
I've tryied with the XMLDocument object but it's not enough for what I want to do.
So now I want to read it as a dataset but I need an XML Schema.
So my question, is it possible to build an XLT file from an XML file ?
Thx
Sybux
|
|
|
|
|
Open your XML data file in Studio, you said you're using VB .NET so I have to assume your using Visual Studio here as well ... anyway, right-click and select the Create Schema option; this will build an XSD file from the XML file. Once you've done that, and the XSD is open in the editor, you can make changes as you see fit.
When your done with your changes to the XSD, right-click, select the Generate DataSet. Go to the form you want to use the DataSet on and drop a DataSet component on the form. From the typed drop-down list, select your XSD file and you're ready to go.
Hope this helps(?)
D.
|
|
|
|
|
I have an XML schema in a C# project in Visual Studio .NET and I want to populate a combobox using enumerations contained in the schema. Any ideas on how to do this ?
Thanks
PS : I am VERY new to C# and XML so take it easy ...
|
|
|
|
|
You can use XmlDataDocument class to impotr XML file to a DataSet and set the datasource of ComboBox with DataSet. I'm not sure what do you mean by enumeration in Schema?!
Hope it helps
Mazy
No sig. available now.
|
|
|
|
|
I want to convert a text based protocol into XML, using C#, how do I do that in the best maner ?
Can I use XSLT in any way ? or do I have to make an parser that converts the file manually ?
An example of the text file:
BORN ANTAL AXLAR = 220
VARMGÅNG
TJUVBROMS
TEST EFTER TÅG !!
FELKODER
W00 T02
VARMGÅNGS MÄTVÄRDEN ANTAL AXLAR = 220 TÅGRIKTNING = U
LH097 023 029 030 029 026 031 017 030 022 029 033 027 032 027 025 020 033 034 029 024 031 028 027 024 031 027 020 024 033 037 031 019 027 026 022 022 032 024 022 019 032 026 024 029 029 028 029 024 032 031 028 027 032 031 021 026 031 029 023 027 030 032 025 022 025 031 027 024 039 032 023 025 032 029 023 027 029 038 025 028 028 027 024 024 034 025 020 029 028 037 025 028 035 031 023 025 024 026 023 023 030 032 025 021 039 033 022 027 035 026 020 028 031 029 023 024 035 027 027 024 027 026 024 022 033 027 027 025 030 029 030 028 032 028 027 025 030 024 034 026 025 023 024 025 028 029 023 029 036 032 022 027 030 029 028 025 028 027 022 024 035 027 034 028 033 023 022 025 030 025 028 027 032 028 022 027 030 026 020 029 029 028 025 024 016 017 013 012 018 012 011 015 016 012 014 013 019 012 013 013 014 011 011 013 036 027 032 029 028 022 024 024 023 017 017 021 032 026 018 025 LV097 028 026 027 033 039 027 031 032 024 025 027 023 037 026 028 023 031 028 025 022 030 028 023 024 028 025 025 026 032 029 024 021 033 022 020 022 034 023 022 021 028 029 026 023 030 027 025 026 033 028 023 019 032 028 023 026 030 023 024 032 030 026 022 024 028 022 020 029 036 032 022 021 038 025 026 025 032 033 026 027 030 020 027 025 038 024 024 029 027 027 019 027 035 021 025 023 034 026 028 026 032 030 028 018 035 031 027 026 029 031 022 024 029 022 023 020 028 031 023 037 028 022 024 020 032 024 021 031 031 028 029 020 032 025 029 022 032 024 032 026 025 025 026 020 031 026 024 026 034 030 022 022 033 026 021 024 034 023 022 020 034 029 025 035 034 021 027 027 032 029 024 024 023 027 028 028 025 023 023 021 032 032 023 023 013 013 008 012 014 013 008 010 013 012 011 010 016 013 009 016 014 010 008 011 046 032 027 027 029 025 024 019 028 010 024 010 033 020 021 022
TJUVBROMS MÄTVÄRDEN
LÅGNIVÅ HS = 047
LÅGNIVÅ VS = 047
ANTAL AXLAR HS = 220
ANTAL AXLAR VS = 220 TÅGRIKTNING = U
TH 002 002 001 001 002 002 002 002 002 002 002 002 001 002 002 001 001 001 001 001 001 001 001 001 002 001 001 001 002 002 002 002 001 001 001 002 001 001 001 001 001 001 002 001 001 001 002 001 001 001 002 002 001 001 001 001 002 001 002 001 002 001 002 001 001 001 002 001 001 001 002 002 001 001 001 001 002 001 002 001 001 002 001 002 001 001 002 001 001 001 002 001 001 001 001 002 001 001 002 001 001 001 001 001 001 001 001 001 001 001 001 001 002 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 002 001 001 001 002 001 001 001 001 002 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 002 002 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 002 001 001 001 001 001 001 001 001 001 001 002 001 001 001 001 001 001 002 001 001 001 002 001 001 001 002 001 002 001 001 001 001 001 001 001 002 001 001 001 TV 001 001 002 001 002 001 003 002 002 002 003 001 003 003 002 001 001 001 003 003 001 001 001 002 003 002 001 001 001 003 003 002 001 001 002 003 002 001 001 001 002 002 002 001 001 002 003 002 001 001 001 002 002 001 001 001 003 002 001 001 002 002 002 001 001 001 003 002 001 001 002 003 001 001 001 001 003 001 001 001 003 003 002 001 002 003 002 001 001 001 002 002 001 001 003 003 001 001 002 003 001 001 001 002 002 001 002 001 002 001 001 001 003 002 001 001 002 003 001 001 001 002 002 001 001 002 003 001 001 001 003 002 001 001 003 003 001 001 002 003 001 001 002 002 001 001 002 003 001 001 002 002 001 001 002 003 001 001 001 003 002 001 002 002 002 001 001 002 002 001 001 001 002 001 002 001 002 001 001 001 002 001 001 001 002 002 002 002 002 001 002 003 001 001 002 003 001 001 002 002 001 001 002 002 001 001 003 002 001 002 002 002 001 001 002 001 002 002 001 001 <.
.
|
|
|
|
|
you have to read the text into your program and convert it into xml.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
now this is a REAL BIG problem
i'm using window XP (hope this is not the reason)
i cant create a file in my computer but it works on my school server
**********************************************
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set OutputXMLFile = fso.CreateTextFile("c:\xx.htm",true)
**********************************************
everytime i run this method my IE hang(???)
so, is it my IIS configuration problem or else
|
|
|
|
|
Set OutputXMLFile = fso.CreateTextFile(@"c:\xx.htm",true);
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Hi
I've just started using DataDynamics ActiveReports for NET which I find very good. However, I'm a bit lost on accessing datasets using XPATH.
Note that I do not want to make my dataset relations nested, and quite often a dataset will contain more than one non-related data table.
Say I have a dataset (dsContracts) with tables/fields as follows
Table - Contracts
Fields - ContractID, Seller, Buyer, Commodity
Table - Details
Fields - ContractID, DetailsID, Grade, Price
Table - Invoices
Fields - ContractID, Invoice, Nett
and that all three tables are related by field ContractID.
I create an xml file by ds.WriteXml("c:\Contracts.xml",WriteSchema)
I would have thought that if I wanted to access dsContracts.Details.Grade the xpath query would be Details/Grade but this is not working.
Could someone give me a clue as to how to access the fields in dataset??
Many thanks in advance
Jeremy Holt
|
|
|
|
|
First of all: you don't use XPath on an XML-Schema, but on the XML file (which can be validated against the Schema).
Now the answer
If the nodeName of your documentElement is Details then it should work. If it's not there are (at least) 2 ways to make it work.
1. Provide the full path: "documentElementNodeName/.../Details/Grade".
Replace "documentElementNodeName" with the actual name of your documentElement and "..." with all elements (if any) till the Details element.
2. Use "//Details/Grade". This finds any Grade element which has a Details parentNode.
|
|
|
|
|
Many thanks your reply - but I still can't get my head around it. I was using the XPath on the XML file.
I wrote a small form to test the expressions using an example in the Help files.
The xsd looks like this (obviously I'm actually accessing the data in the xml).
Using the form below:
/ returns everything as one long string
/* returns only table Images
//* returns everything split into lines
//Journal returns nothing
//Journal/Amount returns nothing
Maybe the code for ProcessFile is wrong ?
Many thanks for your help
Jeremy
<xs:schema id="dsJFinancials" targetNamespace="http://www.tempuri.org/dsJFinancials.xsd" xmlns:mstns="http://www.tempuri.org/dsJFinancials.xsd" xmlns="http://www.tempuri.org/dsJFinancials.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
- <xs:element name="dsJFinancials" msdata:IsDataSet="true">
- <xs:complexType>
- <xs:choice maxOccurs="unbounded">
- <xs:element name="Images">
- <xs:complexType>
- <xs:sequence>
<xs:element name="Beneficiary" type="xs:int" />
<xs:element name="Image" type="xs:base64Binary" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="Journal">
- <xs:complexType>
- <xs:sequence>
<xs:element name="JournalID" type="xs:int" />
<xs:element name="Cno" type="xs:string" minOccurs="0" />
<xs:element name="Ino" type="xs:int" minOccurs="0" />
<xs:element name="BankCodeID" type="xs:int" minOccurs="0" />
<xs:element name="ChargeCustID" type="xs:int" minOccurs="0" />
<xs:element name="Cheque" type="xs:string" minOccurs="0" />
<xs:element name="Date" type="xs:dateTime" />
<xs:element name="IsFullyPaid" type="xs:boolean" />
<xs:element name="Idnote" type="xs:string" minOccurs="0" />
<xs:element name="Nett" type="xs:decimal" />
<xs:element name="VATAmount" msdata:ReadOnly="true" type="xs:decimal" minOccurs="0" />
<xs:element name="PaidTno" type="xs:int" minOccurs="0" />
<xs:element name="IsPrinted" type="xs:boolean" minOccurs="0" />
<xs:element name="ReceivedDate" type="xs:dateTime" minOccurs="0" />
<xs:element name="IsReconciled" type="xs:boolean" />
<xs:element name="Notes" type="xs:string" minOccurs="0" />
<xs:element name="UserInitials" type="xs:string" />
<xs:element name="UserLocation" type="xs:string" />
<xs:element name="VATRate" type="xs:decimal" />
<xs:element name="BankReference" type="xs:string" minOccurs="0" />
<xs:element name="DbCurr" msdata:ReadOnly="true" type="xs:string" minOccurs="0" />
<xs:element name="CrCurr" msdata:ReadOnly="true" type="xs:string" minOccurs="0" />
<xs:element name="Amount" msdata:ReadOnly="true" type="xs:decimal" minOccurs="0" />
<xs:element name="ExRate" type="xs:decimal" minOccurs="0" />
<xs:element name="LookupRate" msdata:ReadOnly="true" type="xs:decimal" minOccurs="0" />
<xs:element name="AccountID" msdata:ReadOnly="true" type="xs:int" minOccurs="0" />
<xs:element name="ContraAccountID" msdata:ReadOnly="true" type="xs:int" minOccurs="0" />
<xs:element name="DebitID" type="xs:int" />
<xs:element name="CreditID" type="xs:int" />
<xs:element name="ConvertRate" msdata:ReadOnly="true" type="xs:boolean" minOccurs="0" />
<xs:element name="DebitAmount" msdata:ReadOnly="true" type="xs:decimal" minOccurs="0" />
<xs:element name="CreditAmount" msdata:ReadOnly="true" type="xs:decimal" minOccurs="0" />
<xs:element name="IsBankToBank" msdata:ReadOnly="true" type="xs:boolean" minOccurs="0" />
<xs:element name="DebitGroupID" msdata:ReadOnly="true" type="xs:int" minOccurs="0" />
<xs:element name="CreditGroupID" msdata:ReadOnly="true" type="xs:int" minOccurs="0" />
<xs:element name="ContraGroupID" msdata:ReadOnly="true" type="xs:int" minOccurs="0" />
<xs:element name="ContraCurrency" msdata:ReadOnly="true" type="xs:string" minOccurs="0" />
<xs:element name="ContraAccountDescription" type="xs:string" minOccurs="0" />
<xs:element name="AccountDescription" type="xs:string" minOccurs="0" />
<xs:element name="RunningBalance" type="xs:decimal" minOccurs="0" />
<xs:element name="DaysUnpaidText" type="xs:string" minOccurs="0" />
<xs:element name="DaysUnpaid" type="xs:int" minOccurs="0" />
<xs:element name="USDAmount" type="xs:decimal" minOccurs="0" />
<xs:element name="USDExRate" type="xs:decimal" minOccurs="0" />
<xs:element name="Reference" type="xs:string" minOccurs="0" />
<xs:element name="MonthDate" type="xs:dateTime" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <Journal>
<JournalID>33993</JournalID>
<Cno>KK041085</Cno>
<Ino>90777</Ino>
<Date>2003-08-24T00:00:00.0000000-03:00</Date>
<IsFullyPaid>false</IsFullyPaid>
<Idnote>D</Idnote>
<Nett>63930.0000</Nett>
<VATAmount>0</VATAmount>
<PaidTno>0</PaidTno>
<IsReconciled>false</IsReconciled>
<UserInitials>JH</UserInitials>
<UserLocation>B</UserLocation>
<VATRate>0</VATRate>
<DbCurr>$</DbCurr>
<CrCurr>$</CrCurr>
<Amount>63930.0000</Amount>
<LookupRate>1.00000000</LookupRate>
<AccountID>198</AccountID>
<ContraAccountID>712</ContraAccountID>
<DebitID>198</DebitID>
<CreditID>712</CreditID>
<ConvertRate>false</ConvertRate>
<DebitAmount>63930.000000000000</DebitAmount>
<CreditAmount>0</CreditAmount>
<IsBankToBank>false</IsBankToBank>
<DebitGroupID>13</DebitGroupID>
<CreditGroupID>21</CreditGroupID>
<ContraGroupID>21</ContraGroupID>
<ContraCurrency>$</ContraCurrency>
<ContraAccountDescription>Sale of goods</ContraAccountDescription>
<AccountDescription>Company Ltd</AccountDescription>
<RunningBalance>1424917.550000000000</RunningBalance>
<USDAmount>63930.000000000000</USDAmount>
<USDExRate>1</USDExRate>
<Reference>024158.001/024158.000</Reference>
<MonthDate>2003-08-01T00:00:00.0000000-03:00</MonthDate>
</Journal>
Public Class frmXPath
Inherits System.Windows.Forms.Form
Private _xp As Xml.XmlDataDocument
Private _nav As XPathNavigator
Private Property XPDoc() As Xml.XmlDataDocument
Get
Return _xp
End Get
Set(ByVal Value As Xml.XmlDataDocument)
_xp = Value
_nav = Value.CreateNavigator
End Set
End Property
Private ReadOnly Property Nav() As XPathNavigator
Get
Return _nav
End Get
End Property
Private Sub frmXPath_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New dsJFinancials
ds.ReadXml("c:\VSReports\dsFinancials.xml")
Me.XPDoc = New Xml.XmlDataDocument(ds)
End Sub
Private Sub ProcessFile()
Try
Dim expr As XPathExpression = Me.Nav.Compile(Me.txtExpression.Text)
Dim iterator As XPathNodeIterator = Me.Nav.Select(expr)
Dim sb As New System.Text.StringBuilder
While iterator.MoveNext
Dim nav2 As XPathNavigator = iterator.Current.Clone
nav2.MoveToFirstChild()
sb.Append(String.Format("{0} {1}", nav2.Value, nav2.Name))
sb.Append(vbCrLf)
End While
Me.txtOutput.Text = sb.ToString
Catch ex As XPathException
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub btnOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOK.Click
Me.ProcessFile()
End Sub
End Class
|
|
|
|
|
I've tested your XML in XMLSPY (and MSXML4) and tried the XPath and it returns the correct node.
So I guess it's the ProcessFile function.
Can't help you with that because I don't have VS.NET.
|
|
|
|
|
OK - thanks very much for your help
Jeremy
|
|
|
|
|
Please tell me wat's wrong with the code below
I'd try both way in the asp file to delete the childnode in xml but it couldn't work
*** News.xml ***
-------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v4.2 -->
<News>
<Article>
<Head>Test 1</Head>
<Des>Testing 123</Des>
<Date>1/9/2003</Date>
</Article>
<Article>
<Head>Test 2</Head>
<Des>Testing 321</Des>
<Date>1/9/2003</Date>
</Article>
</News>
-------------------------------------------------
*** file.asp ***
-------------------------------------------------
<%
If Request.QueryString("Action")="Delete" Then
Dim strID
Dim objXML
Dim subArticle
Dim objLst
Dim subLst
strID = CInt(Request.Form("selectAnnouncement"))
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.Load(Server.MapPath("News.xml"))
**** 01 ****
Set objLst = objXML.getElementsByTagName("Article")
Set subLst = objLst.item(strID)
objXML.documentElement.removeChild subLst
**** 02 ****
'Set subArticle = objXML.documentElement.childNodes(strID)
'objXML.documentElement.removeChild (subArticle)
Set childNode = Nothing
End If
%>
-------------------------------------------------
|
|
|
|
|
try saving the file...
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
... and replace "Microsoft.XMLDOM" with "MSXML2.DOMDocument"
optionally followed by a version number, like "MSXML2.DOMDocument.4.0"
|
|
|
|
|
I am having trouble using column expressions to return an aggregate of child rows in a typed dataset. Here is my scenario:
I have two tables defined in my xsd schema: Orders and Order Details. The relevant fields are:
Orders
- OrderID (primary key)
- Total (expression column)
OrderDetail
- OrderID (foreign key)
- Qty
- PricePerUnit
- ItemTotal (expression column: Qty*PricePerUnit)
my problem is that when I try to set the expression property of the Total column in "Orders" to "Sum(Child.ItemTotal)" and then run the dataset generator, I get the following error: The custom tool 'MSDataSetGenerator' failed. Unbound reference in the aggregate expression 'Sum(child.[ItemTotal])'
I also get this error when referencing the foreign key constaint name: Sum(Child(FK_Orders2OrderDetails).ItemTotal)"
The MSDN library says that my syntax is correct (look up DataColumn.Expression property)
Any ideas? Thanks
|
|
|
|
|
Does anyone know of a c++ API function that replaces xml forbidden chars (<>&'") with their respective entity references (i.e, replacing the & chars with &amp; entity) ?
|
|
|
|
|
I've written a spirit (http://spirit.sourceforge.net) grammar that does that.
You can download it at http://iobind.sourceforge.net
|
|
|
|
|
i'm new to xml and i'm using the hlep files trying to read an xml document but i can't get it to work. everytime it tries to access anything in the xmldoc it errors with an unhandled exception.
here's my code:
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
OpenFileDialog1.ShowDialog();<br />
XmlNodeList nodeList;<br />
XmlDocument doc = new XmlDocument();<br />
doc.LoadXml(OpenFileDialog1.FileName);<br />
<br />
XmlNode root = doc.DocumentElement;<br />
nodeList=root.SelectNodes("members");<br />
<br />
foreach (XmlNode node in nodeList)<br />
{<br />
listBox1.Items.Add(node.Name);<br />
}<br />
}
please help, thanks,
Rob
--
There are 10 kinds of people. Those who understand binary and those who don't. <param name="e" />
<member name="M:Newco.Controls.GroupBoxLine.Dispose(System.Boolean)">
Clean up any resources being used.
<member name="P:Newco.Controls.GroupBoxLine.LineColor">
Specifies the color of the line.
<member name="P:Newco.Controls.GroupBoxLine.TextColor">
Specifies the color of the text.
please help, thanks,
Rob
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|