|
Ok, I wasn't sure what board to put this so I am shooting here first as it is a c# code question:
I have the following XML Data that is returned from a 3rd party API. The resulting data is stored as a string and loaded into the XML dom as follows:
// s_invoices contains the XML
string s_invoices;
XmlDocument doc = new XmlDocument();
doc.InnerXml = s_invoices;
XmlElement root = doc.DocumentElement;
The XML itself looks like the following (sample):
<?xml version="1.0" encoding="UTF-8"?>
<Order_Invoice_Outgoing_Array_Element>
<Order_Invoice_Outgoing_Element>
<interface_transaction>18399</interface_transaction>
<transaction>18399</transaction>
<order_Invoice_Header>
<vendor>P00621</vendor>
<invoice>90951282</invoice>
<currency>USD</currency>
<invoice_Category>ORDER</invoice_Category>
<invoice_Date>2003-08-18T00:00:00.000-04:00</invoice_Date>
<invoice_Due_Date>2003-0818T00:00:00.00004:00</invoice_Due_Date>
<terms>NET30</terms>
<invoice_Amount_Total>6260</invoice_Amount_Total>
<status>CLOSED</status>
<currency_Exchange_Rate>1</currency_Exchange_Rate>
<order_Type_Optional>PO</order_Type_Optional>
<order_Number_Optional>40845</order_Number_Optional>
<pay_Indicator>AP</pay_Indicator>
<original_Invoice_Amount>0</original_Invoice_Amount>
<GL_Account>
<GL_Company>443120</GL_Company>
<GL_Expenditure>809</GL_Expenditure>
<GL>0</GL>
<GL_Cost_Center>0</GL_Cost_Center>
<GL_Description>REPAIR ORDERS</GL_Description>
<GL_Category>ALL</GL_Category>
<modified_By>GLACCOUNT</modified_By>
</GL_Account>
<voucher>78086</voucher>
<created_By>TGREEN</created_By>
<created_Date>2003-10-31T00:00:00.000-05:00</created_Date>
<modified_By>PFAPHSTN</modified_By>
<modified_Date>2006-03-19T00:00:00.000-05:00</modified_Date>
<line_Sum>6260</line_Sum>
<AP_System_Received_Flag>false</AP_System_Received_Flag>
<paid_Flag>true</paid_Flag>
<interface_Batch>14975</interface_Batch>
</order_Invoice_Header>
<order_Invoice_Lines>
<order_Invoice_Line>
<order_Type>PO</order_Type>
<order_Line>7</order_Line>
<order_Number>40845</order_Number>
<invoice_Category>ORDER</invoice_Category>
<invoice_Date>2003-08-18T00:00:00.000-04:00</invoice_Date>
<invoice_Amount>6260</invoice_Amount>
<invoiced_Qty>1</invoiced_Qty>
<GL_Account>
<GL_Company>443120</GL_Company>
<GL_Expenditure>809</GL_Expenditure>
<GL>0</GL>
<GL_Cost_Center>0</GL_Cost_Center>
<GL_Description>REPAIR ORDERS</GL_Description>
<GL_Category>ALL</GL_Category>
<modified_By>GLACCOUNT</modified_By>
</GL_Account>
<status>CLOSED</status>
<assigned_To>VHAINES</assigned_To>
<credit_Memo>78086</credit_Memo>
<credit_Memo_Cost>0</credit_Memo_Cost>
<original_Invoice_Amount>0</original_Invoice_Amount>
<created_By>TGREEN</created_By>
<created_Date>2003-10-31T00:00:00.000-05:00</created_Date>
<modified_By>PFAPHSHD</modified_By>
<modified_Date>2006-03-19T08:39:39.000-05:00</modified_Date>
<line_Amount>6260</line_Amount>
</order_Invoice_Line>
</order_Invoice_Lines>
</Order_Invoice_Outgoing_Element>
</Order_Invoice_Outgoing_Array_Element>
So basically it is a very convoluted XML string. Now what I want to do is populate the XML into a form but am having problems finding what I am looking for.
I am currently using the following:
Console.WriteLine(" The terface_transaction : {0}", root.GetAttribute("//Order_Invoice_Outgoing_Array_Element/Order_Invoice_Outgoing_Element/interface_transaction"));
To try to write out just the interface transaction portion of the XML but alas it is not working. I am thinking it is because maybe GetAttribute is set to start at root and somehow my pathing is wrong, any ideas?
-- modified at 10:38 Tuesday 18th April, 2006
|
|
|
|
|
Hi,
hard to read that XML stuff without proper formmating but I think the caus is that interface_transaction isn't an attribute - it's a node. Although I don't know the error message (you should have specified it instead of 'not wokring') I assume it should be something like:
root.SelectSingleNode("Order_Invoice_Outgoing_Array_Element/"
+ "Order_Invoice_Outgoing_Element/interface_transaction").Value
This should give you the text. You could also split the query to further verify where the problem lies:
XmlNode firstNode = root.SelectSingleNode("Order_Invoice_Outgoing_Array_Element");
XmlNode secondNode = firstNode.SelectSingleNode("Order_Invoice_Outgoing_Element");
XmlNode thirdNode = secondNode.SelectSingleNode("interface_transaction");
Console.WriteLine(thirdNode.Value);
This way you could step through with the debugger and identify where exactly something is not found.
|
|
|
|
|
One approach you could investigate is as follows:
If the xml is well-formed, and the xml can be defined by a schema, and you have enough time to quickly code a class and a test program, then do this:
The xml that is passed to you would be passed into a stream (search for putting a string to a stream for implementation details)
next create a class that represents the data (you may have to work backwards....create the class, serialize it, then see if it matches the xml)
Next take the stream and feed it into an XmlSerializer to turn it into a C# object. From that point forward you are working with an object instead of screwing around with the DOM.
-- modified at 16:21 Tuesday 18th April, 2006
|
|
|
|
|
:(Newbie to c#:
I was working on an example given from a book and I totally got confused.
Please correct me.
I was under the impression that in c# the default way of passing arrays (like any other element) is "byval".
If we don't mention any thing when passing an array to a method, what is the default way?
like
int[] firstarray = {32,33,34};
firstdouble(firstarray);
what is the difference between this way versus this way?
int[] secondarray = {22,23,22};
seconddouble(ref secondarray);
thanks
nath
bnath
|
|
|
|
|
The default is to pass by value. If you want reference semantics, you can use the ref keyword.
Typically, the ref keyword (similar to the out keyword) is only used with value types (i.e. integer, double, float, etc.) For example:
int i = 5;
Test(i);
Debug.WriteLine(i);
void Test(int param)
{
param = 10;
}
string str = "hello";
Test(str);
Debug.WriteLine(str);
void Test(string param)
{
param = "world";
}
int i = 5;
Test(ref i);
Debug.WriteLine(ref i);
void Test(ref int param)
{
param = 10;
}
string str = "hello";
Test(ref str);
Debug.WriteLine(str);
void Test(ref string param)
{
param = "world";
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: I luv teh choco
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
As you are a beginner just some more infos which might have caused your confusion:
Not having the ref keyword doesn't mean changes to the array aren't affecting the caller. It just means that changing the reference of the parameter doesn't has any effect. If you change the contents of the array the caller will still notice it.
public void DoSomething(int[] values)
{
values = new int[] { 1, 2, 3 };
}
public void DoSomething(int[] values)
{
values[0] = 1;
values[1] = 2;
values[2] = 3;
}
public void DoSomething(ref int[] values)
{
values = new int[] { 1, 2, 3 };
}
|
|
|
|
|
Default is passing by value, but for reference types it means that you pass the value of the reference, e.g. the reference is copied, but the object that it refers to is not.
A reference is basically a pointer to the address where the actual data is stored, so when you pass the array to the method it's just a 32-bit pointer value that is really passed to it. The array itself is never copied.
In both your examples the method you call can alter the contents of the array, but in the second example it can also change the value of the reference, e.g. the secondarray variable.
---
b { font-weight: normal; }
|
|
|
|
|
Please show your ability helping the following program
I use 2 threads, 1 read character from keyboard, 1 output 1 character at a time to console.
How can I pass values from Thread 1 to Thread 2? (I use boolean values but It doesnot work because Thread 2 takes only 1 object parameter)
Is there any other way of doing it?
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Threading;<br />
<br />
namespace SS<br />
{<br />
class Program<br />
{<br />
static string m1 = "\nType a string of text then press Enter. " +<br />
"Type '+' anywhere in the text to quit:\n";<br />
static string m2 = "Character '{0}'";<br />
static string m3 = "Character ";<br />
static char ch;<br />
static int x;<br />
<br />
static bool isM1 = false;<br />
static bool isM2 = false;<br />
static bool isM3 = false;<br />
<br />
static void Main(string[] args)<br />
{ <br />
Console.WriteLine(m1);<br />
<br />
<br />
Thread t1 = new Thread(new ParameterizedThreadStart(Program.ReadInput));<br />
Thread t2 = new Thread(new ParameterizedThreadStart(Program.ReadOutput));<br />
<br />
Console.WriteLine("Thread 1 starting...");<br />
t1.Start(x);<br />
Console.WriteLine("Thread 2 starting...");<br />
t2.Start(x);<br />
<br />
Thread.Sleep(80 * 1000);<br />
}<br />
<br />
public static void ReadInput(object param)<br />
{ <br />
int input = (int)param; <br />
<br />
do<br />
{<br />
input = Console.Read();<br />
<br />
try<br />
{<br />
ch = Convert.ToChar(input);<br />
if (Char.IsWhiteSpace(ch))<br />
{<br />
isM3 = true;<br />
if (ch == 0x0a)<br />
isM1 = true;<br />
}<br />
else<br />
isM2 = true;<br />
}<br />
catch (OverflowException e)<br />
{<br />
Console.WriteLine("{0} Value read = {1}.", e.Message, input);<br />
ch = Char.MinValue;<br />
Console.WriteLine(m1);<br />
}<br />
} while (ch != '+');<br />
<br />
x = input;<br />
}<br />
<br />
public static void ReadOutput(object param1)<br />
{<br />
int output = (int)param1;<br />
<br />
if (isM3)<br />
{<br />
Console.WriteLine(m3, output);<br />
}<br />
<br />
if (isM1)<br />
{<br />
Console.WriteLine(m1);<br />
}<br />
<br />
if (isM2)<br />
{<br />
Console.WriteLine(m2, ch, output);<br />
}<br />
<br />
}<br />
}<br />
}<br />
eric
|
|
|
|
|
You can pass a boolean as the object parameter to the thread. You can then cast the object back to boolean when the other thread receives it.
|
|
|
|
|
I'm not directly getting what you are trying to achieve but if the only problem is that you can pass only one parameter to your thread function you could just pack more info into that one object parameter:
public void StartMyThread()
{
int param1 = 0;
bool param2 = false;
string param3 = "Hello World!";
t2.Start(new object[] { param1, param2, param3 } );
}
public static void MyThreadFunction(object paramAll)
{
object[] paramArray = (object[])paramAll;
int param1 = (int)paramArray[0];
int param2 = (bool)paramArray[1];
int param3 = (string)paramArray[2];
}
This works because an object array is also an objectand thus you can stuff as many parameters as you want into the call.
A bit more typesafe variant would be:
public struct ThreadFuncParameters
{
public int Param1;
public bool Param2;
public string Param3;
}
public void StartMyThread()
{
ThreadFuncParameters params = new ThreadFuncParameters();
params.Param1 = 0;
params.Param2 = false;
params.Param3 = "Hello World!";
t2.Start(params);
}
public static void MyThreadFunction(object paramAll)
{
ThreadFuncParameters params = (ThreadFuncParameters)paramAll;
int param1 = params.Param1;
int param2 = params.Param2;
int param3 = params.Param3;
}
I would prefer that way because you wouldn't cast so often as in the first example and casts are always a source for runtime exceptions.
|
|
|
|
|
Thanks so much Robert
I'm doing now
eric
|
|
|
|
|
I've got a problem.
How can I pass variables from ReadInput function to ReadOutput function via struct?
Please help.
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace ConsoleApplication9
{
class Program
{
static string m1 = "\nType a string of text then press Enter. " +
"Type '+' anywhere in the text to quit:\n";
static string m2 = "Character '{0}'";
static string m3 = "Character ";
public struct ThreadFuncParameters
{
public static char ch;
public static int x;
public static bool isM1 ;
public static bool isM2 ;
public static bool isM3 ;
}
static void Main(string[] args)
{
Console.WriteLine(m1);
ThreadFuncParameters pas = new ThreadFuncParameters();
pas.ch = 'a' ;
pas.x = 0;
pas.isM1 = false;
pas.isM2 = false;
pas.isM3 = false;
Thread t1 = new Thread(new ParameterizedThreadStart(Program.ReadInput));
Thread t2 = new Thread(new ParameterizedThreadStart(Program.ReadOutput));
Console.WriteLine("Thread 1 starting...");
t1.Start(pas);
Console.WriteLine("Thread 2 starting...");
t2.Start(pas);
}
public static void ReadInput(object paramALL)
{
ThreadFuncParameters par = (ThreadFuncParameters)paramALL;
char p1 = par.ch;
int p2 = par.x;
bool p3 = par.isM1;
bool p4 = par.isM2;
bool p5 = par.isM3;
do
{
p2 = Console.Read();
try
{
p1 = Convert.ToChar(p2);
if (Char.IsWhiteSpace(p1))
{
p5 = true;
if (p1== 0x0a)
p3= true;
}
else
p4 = true;
}
catch (OverflowException e)
{
Console.WriteLine("{0} Value read = {1}.", e.Message, p2);
p1 = Char.MinValue;
Console.WriteLine(m1);
}
} while (p1!= '+');
ch = p1;
x = p2;
isM1 = p3;
isM2 = p4;
isM3 = p5;
}
public static void ReadOutput(object paramALL)
{
ThreadFuncParameters par = (ThreadFuncParameters)paramALL;
char p1 = par.ch;
int p2 = par.x;
bool p3 = par.isM1;
bool p4 = par.isM2;
bool p5 = par.isM3;
if (p5)
{
Console.WriteLine(m3, p2);
}
if (p3)
{
Console.WriteLine(m1);
}
if (p4)
{
Console.WriteLine(m2, p1, p2);
}
}
}
}
eric
|
|
|
|
|
How to pass parameters between threads greatly depends on what exactly you want to do. As far as I see you are starting both thread paralell where the ReadOutput thread just writes some lines to the console and ReadInput waits for user input. In this scenario ReadOutput will probably be finished before the user can input anything.
Please try to explain what you are actually trying to achieve with your code. Than I will try to give you a good way to achieve your goal.
|
|
|
|
|
Does anyone have experience creating an ebXML message in a soap envelope using a c# client application?
I have a windows app that needs to create, format, and post an ebXML message.
I've looked at a lot of sites (including ebxml.org) and EVERYTHING is java java java.
Any help would be greatly appreciated.
Paul Brower
|
|
|
|
|
hi all,
I have a treeview that I load from a dataset(baiscly files in a dir). I want to use the checkbox option in the treeview, when I uncheck a node it must be disabled. other app. can ask for the exsting nodes, I read this from the dataset not from the treeview.
beqause I load the treeview from a dataset I can not use the on_select method.
is there any way to put the treeview checkbox option in the dataset, and wacht if it change?
so that I can give the correct answer.
thanks
|
|
|
|
|
I don't think there is a direct way to solve this problem. But you could add a boolean column to your DataSet tables and when the check state changes in the tree you could change the values in this column. This way other components using the DataSet would just need to react on the RowChanged event.
|
|
|
|
|
but the problem is that the treeview get it's nodes from the dataset.
on startup I can have several nodes selected and other not.
how can I catch this.
|
|
|
|
|
hi to all,
i'm trying to select all the text in a textbox control (winform) on the enter event.
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.TextLength;
when the enter event of the textbox si fired with the tab, the text is selected correctly.
but when the enter event of the textbox si fired with the mouse click, no text will be selected in textbox
does any body knows why ? if yes can you tell me what the solution is ?
best regards and thanks in advance
fady sayegh
|
|
|
|
|
That's by design I think. I'll let you know if I think of a work-a-round.
Ed
|
|
|
|
|
The MouseClick event happens after the Enter event. This is so that the user can click where they want the cursor to be positioned. Try placing your code in the MouseClick event.
----------
There go my people. I must find out where they are going so I can lead them.
- Alexander Ledru-Rollin
|
|
|
|
|
You can postpone the text selection until after the mouse event processing occurs, which ensures that clicking into the TextBox will have the same effect as tabbing into it.
private void textBox1_Enter(object sender, System.EventArgs e)
{
this.textBox1.BeginInvoke( new MethodInvoker( this.textBox1.SelectAll ) );
}
Josh
|
|
|
|
|
|
lots of frustration and angst!!!
I have the answer for you...just solved it in my game I'm writing. Unfortunately my machine died last night (and is now on the curb for trash pickup) and the answer is sitting on my couch in the drive cage!!!
I had to tinker with things a bit but I did get it to work.
Ahhh I remember now....
private void myTextbox_Enter( object sender, MouseEventArgs args )
{
myTextBox.SelectAll();
}
That should do it for you. Darn inconsistant behaviour!!
|
|
|
|
|
Hi
I'm working with Crystal reports and c# windows application. my report is bind using stored procedure to database that accepts 3 parameters. Now I want to add one more stored procedure with same 3 parameters to this report. but crystal report gives following error :
Description: One of the parameter is not supplied
SQL State: 42000
Native Error: 201 [Database Vendor Code: 201]
Can anybody know how to solve this issue?
Warm Regards
Abhijeet B.
|
|
|
|
|
Hi,
I'm starting a process with ProcessStartInfo, setting the 'Arguments' property to a filepath to the file I want to start the process with. However, the process I start is complaining about the filepath - since the filepath has spaces in it, it only seems to pass to the process the filepath upto the first space, and then ignores the rest. The process I'm trying to start is regsvr32.exe and the argument is a filepath to a dll I want to register. Could anyone please help me?
Thanks a lot,
Shehzad
|
|
|
|