|
I use a ISAXXMLReader to locate the line & column number of a IXMLDOMNode;
for that i use a ISAXLocator that is transmitted to the ContentHandler :
// create a reader & ContentHandler:
ISAXXMLReaderPtr pReader;
HRESULT hr = pReader.CreateInstance(__uuidof(SAXXMLReader40));
MyContentHandler *pMyContentHandler = new MyContentHandler();
hr = pReader->putContentHandler(pMc);
// create a ISAXLocator & put it to the ContentHandler :
ISAXLocatorPtr pLocator;
hr = pLocator.CreateInstance(__uuidof(ISAXLocator)); // -> hr = -2147221164
pMyContentHandler->putDocumentLocator(pLocator);
// pass a node to the parser :
_variant_t v;
v.vt = VT_DISPATCH;
v.pdispVal = pNode;
pNode->AddRef();
hr = pReader->parse(v);
The parser works (it directly goes to the specifed node),
but pLocator.CreateInstance fails (hr = -2147221164). What's wrong with it ?
JPG
|
|
|
|
|
In fact the code returned by pLocator.CreateInstance
is REGDB_E_CLASSNOTREG : the ISAXLocator is not registered.
Yet the ISAXXMLReader class is registered.
Indeed, looking in the registry, the uuid of ISAXXMLReader is found, but not
the uuid of ISAXLocator.
All these classes were normally installed with the MSXML 4.0 SP2 Parser and SDK
(msxml.msi) from Microsoft.
Does the ISAXLocator need a special trick to be registered ?
JPG
|
|
|
|
|
Hi all,
I have designed a file *.aspx contains a DBGrid control and a XML control. Both of them are server control.
I stored some data into XML tag and now want to show them on DBGrid. But DBGrid.DataSource property accept only DataSet, DataView, etc.
Please tell me how to translate data from XML into DBGrid.
Thank you
Trong Tuan
|
|
|
|
|
Does anyone have a need to transform DTD's (not schema) into C# classes and interfaces?
I had to work on a old (but important) set of DTD's recently and developed a pretty thorough program to handle this. If there is an interest, I will clean it up and get it out.
|
|
|
|
|
I am trying to use MSXML4 parser(DOM). I have successfully used Expat and I trying to figure out how to parse the following using DOM.
<Theme>
<Directory name="mcev1"/>
<Dimensions width="800" height="600"/>
<Background image="background.bmp"/>
<Overlay1 image="lay1.bmp" x="0" y="0"/>
<Overlay2 image="lay2.bmp" x="0" y="500"/>
<Unselectedborder A="255" R="0" G="0" B="0"/>
<Selectedborder A="255" R="255" G="255" B="0"/>
<UnselectedGradient A="128" R="255" G="255" B="255"/>
<SelectedGradient A="204" R="0" G="128" B="0"/>
<MainFont name="Arial" size="20" style="Bold" A="255" R="255" G="255" B="255"/>
</Theme>
As I am parsing I know when I have found the Theme node but then I am confused. Do I just loop thru the siblings or what. I can't seem to find an example that answers this question.
-Steve
|
|
|
|
|
if you are using DOM then you should be doing no parsing.
what information/process are you trying to do, do you have any code?
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Philip,
From the examples in MSDN and Code project I have code that loads the XML file, code that walks thru all the nodes and code that can save the tree back to the file.
Since I am used to the Expat way of doing things maybe I am looking at this all wrong. But, if I am not doing any parsing how does the data get from the DOM tree into my data structures?
-Steve
|
|
|
|
|
I guess it might be your use of the word "parsing"
anyway the code could be written in a number of ways, here are a few examples:
XmlDocument doc = new XmlDocument();<br />
doc.load(filepath);<br />
<br />
XmlNode theme = doc.SelectSingleNode("/Theme");<br />
XmlNode directory = theme.SelectSingleNode("Directory");<br />
string dirname = directory.Attributes["name"].Value;<br />
string mainFontName = theme.SelectSingleNode("MainFont/@name").InnerText;<br />
<br />
foreach (XmlNode node in theme.ChildNodes)<br />
{<br />
string name = node.Name;<br />
string firstAttrValue = node.Attributes[0].Value;<br />
}
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Philip,
Thanks, very helpful information. I do however, have a couple of questions about your comments.
First, what version of MSXML are you refering to? I am trying to use the latest and there seems to be several versions of every function.
Philip Fitzsimons wrote:
string mainFontName = theme.SelectSingleNode("MainFont/@name").InnerText;
I don't understand the following code. Specifically (.../@name" ) and .InnerText.
And finally,
Philip Fitzsimons wrote:
foreach (XmlNode node in theme.ChildNodes)
I have not been able to figure out this part either.
How do you loop until you have no more nodes in theme?
Thanks for your help. You have been very helpful.
-Steve
|
|
|
|
|
the @name is to access the attribute as opposed to an element caled name.
.ChildNodes gives back a collection of nodes that are children of theme.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
This must be .net. The sdk I am looking at is not like the one you are mentioning. I guess I failed to mention that I am using MSXML4 in VC++6.
-Steve
|
|
|
|
|
|
After loading a xml file, I get a IXMLDOMNode from a Xpath with the method selectSingleNode.
How to get the corresponding file position in the XML file, and also its line number & character number ?
JPG
|
|
|
|
|
Hi everyone,
I have the following XML structure.
<ROOT>
<ELEMENT>
<Time>100</Time>
<MIN>500</MIN>
<MAX>500</MAX>
<RESULT>OK</RESULT>
<ERRORS>NO</ERRORS>
</ELEMENT>
<ELEMENT>
<Time>100</Time>
<RESULT>OK</RESULT>
<ERRORS>NO</ERRORS>
</ELEMENT>
Unfortunately, as you can see the guy who designed the XML did not make it consistent (all ELEMENT nodes do not have the same sub-nodes). However, I am only interested in the RESULT sub-node.
So, I use the XMLDataDocument class to step through the file.
My question is that when I step in the element node, how can I just take a look at the RESULT tag.
Thanks for any help you can give me.
Pankaj
Without struggle, there is no progress
|
|
|
|
|
I would edit your post and check 'Do not treat <'s as HTML tags'. Makes markup a little easier to read
Ryan
|
|
|
|
|
Thanks for pointing that out. Did not even think about it
Pankaj
Without struggle, there is no progress
|
|
|
|
|
You can use XmlDocument's selectNodes("//RESULT") and it will bring you all 'RESULT' nodes despite where they are in the document structure.
Trying to make bits uncopyable is like trying to make water not wet.
-- Bruce Schneier
By the way, dog_spawn isn't a nickname - it is my name with an underscore instead of a space. -- dog_spawn
|
|
|
|
|
Hi Daniel,
Thanks for the reply, despite my hard to read post!
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Hi,
I tried the SelectNodes and SelectSingleNode method. However, it starts its search from the root document. However, I want it to search only in its own node context. Am I missing something here?
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
I have a .net web service which expects a soap requested outlined by a structure of classes. Working on the client side I have created an xml file that contains everything that will be in the body of the soap envelope. If possible I want to take the contents of the xml file and shove them directly into the class and send it the web service. Here is the code I have been trying.
<br />
Dim sXMLFile As String = txtXML.Text<br />
Dim doc As New XmlDocument()<br />
Dim rc As localhost.Request<br />
<br />
Dim ds As New DataSet()<br />
Dim tbl As DataTable<br />
Dim col As DataColumn<br />
Dim row As DataRow<br />
<br />
doc.Load(sXMLFile)<br />
ds.ReadXml(New XmlNodeReader(doc))<br />
<br />
''
'rc.SetInfo = ds.Tables(0).DataSet<br />
'rc.SetInfo2 = ds.Tables(1).DataSet<br />
<br />
''
''
'wr.SubmitRequest(ctype(ds, localhost.Request)<br />
'wr.SubmitRequest(ctype(sXMLFile, localhost.Request)<br />
wr.SubmitRequest(ctype(XmlNodeReader(doc), localhost.Request)<br />
Is this possible and if so how?
Thanks,
Jason W.
|
|
|
|
|
Yep, its possible. Do you have the WSDL for the method in question? You will need to use the correct schema.
If you have the WSDL however, it would probalby be a better idea to generate a proxy and use that, much more maintainable.
Ryan.
|
|
|
|
|
Actually, I finally figured out how to do it this morning. Here is what I came up with:
Dim sXMLFile As String = txtXML.Text<br />
Dim serializer As New XmlSerializer(GetType(localhost.RequestChange))<br />
Dim fs As New FileStream(sXMLFile, FileMode.Open)<br />
Dim rc As localhost.RequestChange<br />
rc = CType(serializer.Deserialize(fs), localhost.RequestChange)
Thanks for the response,
Jason W.
|
|
|
|
|
I need to accept XML formatted data over a socket connection and place the data into a dataset for parsing. The XML data is bracketed by a start character and an end character, but may range from 50 bytes to thousands of bytes. The app will need to be in c++. ANy ideas
Thanks
|
|
|
|
|
Just grab the XML and use DataSet.ReadXml to load it into a DataSet object. You can use the socket stream as the parameter, or use any TextReader (such as the XmlTextReader ) as the parameter. Just see the ReadXml for the overloads.
-----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-----
|
|
|
|
|
I’m hitting my .Net web service with a .Net client app I developed and am getting the following error.
A first chance exception of type 'System.ObjectDisposedException' occurred in system.dll<br />
Additional information: Cannot access a disposed object named "System.Net.Sockets.NetworkStream".
Any Ideas why it is occurring?
Thanks,
Jason W.
|
|
|
|