MSXML problem in VC++ 6 - c++

I have this bit of code:
typedef CComQIPtr<MSXML::IXMLDOMDocument2> XML_DocumentPtr;
then inside some class:
XML_DocumentPtr m_spDoc;
then inside some function:
XML_NodePtr rn=m_spDoc->GetdocumentElement();
I cannot find anywhere in the MSDN documentation what that GetDocumentElement() is supposed to do? Can anyone tell me why it doesn't seem to be part of IXMLDOMDocument2 interface?
And which interface does have it?

IXMLDocument2 inherits from IXMLDocument. The GetDocumentElement() method is defined in that interface. See here.
Basically GetdocumentElement returns the root element of the XML document.
The property is read/write. It returns
an IXMLDOMElement that represents the
single element that represents the
root of the XML document tree. It
returns Null if no root exists.
When setting the documentElement
property, the specified element node
is inserted into the child list of the
document after any document type node.
To precisely place the node within the
children of the document, call the
insertBefore method of theIXMLDOMNode.
The parentNode property is reset to
the document node as a result of this
operation.

GetdocumentElement returns the root element of the document or NULL if no root exists.

Related

Deleting a node based on child value in Pugixml

What I have so far can delete all the children of the actual node I want to delete but not the node itself.
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("config/config.xml");
pugi::xpath_query query_network_last_run("//state[network/network_last_run='2']");
pugi::xpath_node_set network_last_run = query_network_last_run.evaluate_node_set(doc);
The part below removes specific parts -- but I want to delete the network based on a child value (network_last_run), not this child of it.
network_last_run[0].node().remove_child("network_gateway");
XML file structure
<root>
<state>
<network>
<network_last_run>2<network_last_run>
<network_gateway>192.168.3.1</network_gateway>
</network>
</state>
</root>
I tried to step back up using
network_last_run[0].node().parent().remove_child("network");
But it seems that only modifies the actual structure stored in memory, (removes the first one) and not the structure the query has.
I could probably do this in a for loop and use an if condition to check whether the child node value matches, but I would like to do it through a query if possible?
After playing around with it a bit, this is the solution I made (and I couldn't find an answer to this anywhere else so I figured I could just post it here)
Essentially it changes the name of the actual node in question. After that, it runs a query (the node set of which could be used in a for loop) and removes any child elements with the new name.
network_last_run[0].node().set_name("removal");
pugi::xpath_query query_removals("//state");
pugi::xpath_node_set removals = query_removals.evaluate_node_set(doc);
removals[0].node().remove_child("removal");

Getting the main list of nodes from xml document, using msxml lib in c++

I would like to go through the whole xml document that I have, without depending in the actual id value, node name or attributes.
I use the msxml3 lib.
I would like to get a list of the main nodes in the xml, that are descendants of the main node.
<mainNode>
<firstNodeInList></firstNodeInList>
<secondNodeInList></secondNodeInList>
<thirdNodeInList></thirdNodeInList>
</mainNode>
I would like to get a list of the inside nodes, i.e. :
firstNodeInList->secondNodeInList->thirdNodeInList.
Thank you
Since no one responded, I had to find out the answer, which apperently is very simple.
The first line will get the document element, or the root element. The second will get the list of children of the root.
MSXML2::IXMLDOMElementPtr docElem = m_newFileDoc->documentElement;
MSXML2::IXMLDOMNodeListPtr nodes = docElem->childNodes;

How do I rotate/translate existing OpenSceneGraph (OSG) nodes from a loaded .ive model tree?

I have a given model in .ive and the problem is that I'm trying to rotate a single node out of the whole tree model (existing in the .ive file). Is that possible? How can I do that?
Sure, it can be done.
You first have to find the nodes that you want to manipulate. You should be able to do this by creating a subclass of osg::NodeVisitor, and using it to traverse the graph until you find the node you want to manipulate. If you've given the node a name, it can be simple to find the one you are looking for. If not, you'll have to figure out some other unique characteristics of the node, or just pull all nodes of a certain type and try them one at a time.
Then, once you have that, you can just save a pointer and manipulate it directly.
See tutorials:
https://www.movesinstitute.org/Sullivan/OSGTutorials/osgDOF.html
and
https://www.movesinstitute.org/Sullivan/OSGTutorials/osgUpdate.htm
You will have to find the node that corresponds with that subsection of the model. To do this you will need to identify something that is unique about that node (hopefully it has a name or something).
Once you have that node, you may need to break it off of the main tree, add a Transform of some kind (a PositionAttitudeTransform, probably) and then re-add your node as a child of the PAT.
Then you can modify the rotations in the PAT.
You might use a visitor like the find named node(s) visitor to locate the node you want.
Consider converting the .ive file to .osgt or .osg in order to see the structure (and hopefully node names) in the file.

Retrieving PCDATA xpath via the c++ pugixml library

I spent the last week reading and re-reading the pugixml documentation and I can find no method of retrieving the PCDATA with xpath.
Please explain would I pull the text from title:
<html><head><title>Hello!</title></head></html>
Last time I asked this question the only answers I got referred to generic xpath queries, rather than specifically to the pugixml library functions. I've read the xpath documentation thoroughly, so don't worry about educating me about it.
Thanks.
const char* text = doc.select_single_node("html/head/title/text()").node().value();
select_single_node selects the PCDATA node
.node() converts from xpath_node to xml_node (this is necessary since XPath nodes are either xml nodes or attributes)
.value() gets the value of the node (i.e. text).
What I did when I was fetching PCDATA i first found the node, and after that I called
node = retrive_xml_node_from_xpath();
node.first_child().value;
So for the example you show create an xpath to find the title node, and then get its first childs value.

XSLT - How can I save a node from one document in another temp document and later retrieve it?

This isn't exactly what I want to do, but it's a simple case of the functionality I need. I want to alternate between processing nodes in one document and processing nodes in a temp document that was created during the processing of the original document. To do this, I want to "save" a node from the original document into the temp document so I can go back to it. I can easily "save" the node itself into the temp document, but being part of the temp document I can no longer do things like test if another node is an ancestor of that node in the original document.
I could imagine using generate-id to do this. I wouldn't save the node per se, but an id to it and then use the id to get back to the node within the original document. The problem with this approach is that I can't ask for the node whose generate-id is such and such. I could go through the tree and find it, but I'm looking for a simpler, faster access method.
Does one exist?
Thanks in advance.
Index every node of interest by its generate-id():
<xsl:key name="kNodeById" match="node()"
use="generate-id()"/>
and to get to the node by its id $vId:
key('kNodeById', $vId)