|
This article[^] just appeared on CodeProject; it shows how to marshal multiple strings using C++.
I havent read it yet, but from its length you might conclude it is not all that easy; I dont
think it being C++ code (rather than C#) adds to the complexity...
So I maintain my earlier suggestions.
Luc Pattyn
|
|
|
|
|
Hi,
I'm a noob and desparately need help with this.
I have an XML file and I'm suppose to select the element attrib(<link href="XXX_SUMMARY.xml" /> from node with title="Summary". Attached below is sample of the XML. Can anyone pls help me. I'm at a loss.
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>XXX</title>
<link rel="alternate" href="http:xxx.xml" />
<link rel="next" href="http://xxx.xml" />
<dc:creator>XXX</dc:creator>
<entry>
<title>Jam</title>
<link href="XXX_JAM.xml" />
<category term="Route" scheme="521" />
<category term="TimeStamp" scheme="20070201101329430" />
<author>
<name>XXX</name>
</author>
<id>XXX_JAM.xml</id>
<published>2007-02-01T02:13:29Z</published>
<summary type="text">Jam Cleared</summary>
<dc:creator>XXX</dc:creator>
<dc:date>2007-02-01T02:13:29Z</dc:date>
</entry>
<entry>
<title>Summary</title>
<link href="XXX_SUMMARY.xml" />
<category term="Route" scheme="137" />
<category term="TimeStamp" scheme="20070201101319852" />
<author>
<name>XXX</name>
</author>
<id>XXX_SUMMARY.xml</id>
<published>2007-02-01T02:13:19Z</published>
<summary type="text">EVENT_SUMMARY</summary>
<dc:creator>XXX</dc:creator>
<dc:date>2007-02-01T02:13:19Z</dc:date>
</entry>
<entry>
<title>Report</title>
<link href="XXX_REPORT.xml" />
<category term="Route" scheme="9" />
<category term="TimeStamp" scheme="20070201100628191" />
<author>
<name>XXX</name>
</author>
<id>XXX_REPORT.xml</id>
<published>2007-02-01T02:06:28Z</published>
<summary type="text" />
<dc:creator>XXX</dc:creator>
<dc:date>2007-02-01T02:06:28Z</dc:date>
</entry>
</feed>
|
|
|
|
|
Google for XPath, that' s the language you use to search XML.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I've tried Xpath but I can't seem to get the correct node...help anyone pls...thanks...
XPathDocument doc = new XPathDocument("sample.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr;
expr = nav.Compile("/feed/entry[title='Summary']");
XPathNodeIterator iterator = nav.Select(expr);
listBox1.Items.Add(iterator.Current.Value);
|
|
|
|
|
Hi,
I don't know exactly what the problem is but it seems to lie somewhere in your xmlns...
I loaded your xml into a XmlDocument and tried to SelectSingleNode("feed") but it wouldn't work. As soon as I removed all the xmlns except the one directly referenced in the doc (xmlns:dc) it worked!
.....further investigation.... more to the point take this out xmlns="http://www.w3.org/2005/Atom" and it should work. I don't know why, must be a conflict of sorts.
|
|
|
|
|
thanks but i still can't get my desired output. actually i want to search for all nodes with <title>=summary and grab the next node attribute<link href> to get the links. The earlier code was a trial to see if i can select a correct node.
can anyone pls kindly help me get the correct link node pls...thanks
-- modified at 20:34 Thursday 1st February, 2007
|
|
|
|
|
The problem is that your top-level element declares a default namespace (xmlns="http://www.w3.org/2005/Atom") that is valid for all nested elements. This means that your feed and entry have a qualified name of "{http://www.w3.org/2005/Atom}feed" or "{http://www.w3.org/2005/Atom}entry" respectively. Your XPath on the other hand is looking for unqualified feed and entry elements i.e. those declared in the empty namespace. Because your document does not contain such elements nothing is found. To resolve this use the overload of the Select method that takes an IXmlNamespaceResolver . Take a look at the example given by the respective MSDN topic and you should be able to work this out.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
sorry but I'm unclear on how to use the IXmlNamespaceResolver. Tried googling for example on the usage but still unclear. Anyone pls kindly point me in the right direction. Thanks.
|
|
|
|
|
part of my code is below:
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.Load("sample.xml");
XmlNamespaceManager nsmanager = new XmlNamespaceManager(myXmlDocument.NameTable);
nsmanager.AddNamespace("ns", "http://www.w3.org/2005/Atom");
XPathNavigator nav = myXmlDocument.CreateNavigator();
XPathExpression expr;
expr = nav.Compile("feed/entry[title='Summary']");
expr.SetContext(nsmanager);
XPathNodeIterator iterator=nav.Select(expr);
XPathNavigator nav2 = iterator.Current.Clone();
listBox1.Items.Add((nav2.Value));
but the output i get contains not only nodes with title=Summary but all the nodes of feed in the XML posted earlier. Can anyone advise how to select <link href> to grab the address from the attribute. thanks.
|
|
|
|
|
As indicated before you have to use the overload of Select that takes an IXmlNamespaceResolver . In your case you pass in the XmlNamespaceManager object. Furthermore you need to qualify the elements in your XPath expression with the prefix defined for their namespace i.e. "ns:feed/ns:entry[ns:title='Summary']".
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I am wanting to use C# to open a page using a browser control (Windows App), call a JavaScript code segment on the page and then allow the code to execute.
Here is program flow:
Open my Windows App.
Browser control opens a page.
Page loads with a java button that when clicked runs the code I want to run.
C# calls the code, or simulates the button click.
Program waits for code execution.
Program exits.
I am not expecting someone to write the code, I just want to clarify that the code I am calling is not actually visible to the C# app I am writing.
Thanks for your time!
The only way to speed up a Macintosh computer is at 9.8 m/sec/sec.
|
|
|
|
|
I did this too.
Assuming that your browser control is named webBrowser1, use
webBrowser.Document.InvokeScript() method
It takes two parameters: the name of the JavaScript function and an array of objects representing it's parameters.
|
|
|
|
|
ComboBox control has got selectedindexchanged event. As the name suggest this event should fire when selected item change for the combobox. But this event fires even when the currently selected item is selected again from the dropdown list of combobox.
e.g.
if I have loaded following items in my combobox say
item1
item2
item3
item4
with item1 as selected when my application starts.
Now if from UI, I again select the "item1" (which is already selected in combo box) then also the selectedindexchanged event fires. In this case the index has not changed still the selectedindexchanged event fires. I find this bit strange.
Is there anyway to findout when the selected item has changed by User. I want some kind of notification when user indeed changes the combobox selected item (not when combobox.selecteditem is set through code)?
regards
KC
|
|
|
|
|
Hi All,
I have created a class which holds a method for impersonating a user and starting a process using the impersonated login.
I'm having a windows application wherein i start a process from my windows login say Process1 and another process using the impersonation method say Process2 (i'm calling notepad.exe in both logins).
When i'm copying a word from the notepad under Process1 and pasting it in the notepad under Process2, it should not get pasted. But instead it gets pasted.
Is there any possiblity that i can restrict the pasting event in the notepad.
Parimala
|
|
|
|
|
I want to make an User Control in VC# that can be used in VC6.
For that I have made a control in C# using 'Windows Control Library', which make dll file; But in VC6 to add a control only OCX files are requird.
So how to make an User Control in VC# that can be used in VC6
|
|
|
|
|
The only way is to create a COM based one. VC6 was written before C# existed, it plainly knows nothing about C#. COM can provide a common interface.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I have a Windows Form application with a simple GUI that contains a progress bar. Pushing the button 'Start' on my form invokes some other project[ in same solution] classes that carry out a lot of calculations and database access. I want to show the user the progress of the program. The program is actually a loop of database migration that are handled.
My solution contains more the one project.
we have different layer.
Presentation layer.
bussines layer.
My question is: How do I make the progress bar update itself from other layer, when we dont have reference in bussines layer?
Thanks in advance for your help
|
|
|
|
|
If you don't have a reference to the business layer, how are you calling it ? If they are both exes, then the design sucks and you need inter process communication to make it work.
Usually, I'd have a business layer DLL and I'd use a delegate to send progress reports back from a worker thread.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Exception Sample :
static void Main(string[] args) {
try{
Console.WriteLine("Level 1");
try {
Console.WriteLine("Level 2");
goto exit;
}
finally {
Console.WriteLine("Level 2 Finished");
}
}
finally {
Console.WriteLine("Level 1 Finished");
}
exit: ;
}
What is the wrong in this code sample above?
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Are you asking @ sytanx or what.. It will compile successfully.
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
hi kulakarni,
thanks for the response.
actually today i took one pre assessment test in C#. they asked this question.
they gave me 5 options:
What is the console output for the code sample above?
Choice 1
Level 1
Level 2
Level 2 Finished
Level 1 Finished
Choice 2
Level 1
Level 2
Level 1 Finished
Choice 3
Level 1
Level 2
Choice 4
Level 1
Level 2
Level 1 Finished
Level 2 Finished
Choice 5
Level 1
Level 2
Level 2 Finished
which one is the correct out put?
Thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
It is obvious choice1. Because of the rule that finally block is always executed inspite of any excpetion is occured or not. In this case, inner most try and finally is executed first and then the outer one.
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
oho....thanks Kulakarni.
i know this but when i saw the question, i didn't understand the question first of all........now i came to know the correct answer!
Thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
The problem is that you are using GOTOs Get over that crutch quickly.
|
|
|
|
|
Hi everyone,
How to get Insert button status?
Thank You.
|
|
|
|