How to get the current line of a xml element / node?
-
How can I get the current line of a xml element / node ? I am working with the MS XML DOM parser! Daniel ;) --------------------------- Never change a running system!
-
How can I get the current line of a xml element / node ? I am working with the MS XML DOM parser! Daniel ;) --------------------------- Never change a running system!
Daniel, First what do you mean by the current line. My assumption is that you mean the text value associated with an element node. Which happens to be the collection of child nodes to that element which are text nodes. So look up in the help section that comes with MSXML4 (which I recommend if you do not have) HRESULT get_childNodes( IXMLDOMNodeList **childList); and then look up TextNode. The first part from one of the sections returned is: XML DOM Enumerated Constants IXMLDOMNodeType enumerations specify valid settings for the Document Object Model (DOM) node type. The node type determines valid values and whether the node can have child nodes. Values The IXMLDOMNodeType enumeration defines the following valid values. NODE_ELEMENT (1) The node represents an element (its nodeTypeString property is "element"). An Element node can have the following child node types: Element, Text, Comment, ProcessingInstruction, CDATASection, and EntityReference. The Element node can be the child of the Document, DocumentFragment, EntityReference, and Element nodes. NODE_ATTRIBUTE (2) The node represents an attribute of an element (its nodeTypeString property is "attribute"). An Attribute node can have the following child node types: Text and EntityReference. The Attribute node does not appear as the child node of any other node type; it is not considered a child node of an Element. NODE_TEXT (3) The node represents the text content of a tag (its nodeTypeString property is "text"). A Text node cannot have any child nodes. The Text node can appear as the child node of the Attribute, DocumentFragment, Element, and EntityReference nodes. So you get the list of child nodes and step through that list. Compare the node type of the child to "NODE_TEXT" (3) and you most of the way there. Once you get the flavor it really does make sense. "I will find a new sig someday."
-
Daniel, First what do you mean by the current line. My assumption is that you mean the text value associated with an element node. Which happens to be the collection of child nodes to that element which are text nodes. So look up in the help section that comes with MSXML4 (which I recommend if you do not have) HRESULT get_childNodes( IXMLDOMNodeList **childList); and then look up TextNode. The first part from one of the sections returned is: XML DOM Enumerated Constants IXMLDOMNodeType enumerations specify valid settings for the Document Object Model (DOM) node type. The node type determines valid values and whether the node can have child nodes. Values The IXMLDOMNodeType enumeration defines the following valid values. NODE_ELEMENT (1) The node represents an element (its nodeTypeString property is "element"). An Element node can have the following child node types: Element, Text, Comment, ProcessingInstruction, CDATASection, and EntityReference. The Element node can be the child of the Document, DocumentFragment, EntityReference, and Element nodes. NODE_ATTRIBUTE (2) The node represents an attribute of an element (its nodeTypeString property is "attribute"). An Attribute node can have the following child node types: Text and EntityReference. The Attribute node does not appear as the child node of any other node type; it is not considered a child node of an Element. NODE_TEXT (3) The node represents the text content of a tag (its nodeTypeString property is "text"). A Text node cannot have any child nodes. The Text node can appear as the child node of the Attribute, DocumentFragment, Element, and EntityReference nodes. So you get the list of child nodes and step through that list. Compare the node type of the child to "NODE_TEXT" (3) and you most of the way there. Once you get the flavor it really does make sense. "I will find a new sig someday."
What I mean is the current line of a xml node / element in the xml file, like the
get_line()
function of theIXMLDOMParseError
return. I read some attributes of a xml node / element and check if they are in the possible range (eg. - 100 < attribute < +100). If the attribute is not in the range I want to display an error with the line, where I read the attribute / node / element! Daniel ;) --------------------------- Never change a running system! -
What I mean is the current line of a xml node / element in the xml file, like the
get_line()
function of theIXMLDOMParseError
return. I read some attributes of a xml node / element and check if they are in the possible range (eg. - 100 < attribute < +100). If the attribute is not in the range I want to display an error with the line, where I read the attribute / node / element! Daniel ;) --------------------------- Never change a running system! -
What I mean is the current line of a xml node / element in the xml file, like the
get_line()
function of theIXMLDOMParseError
return. I read some attributes of a xml node / element and check if they are in the possible range (eg. - 100 < attribute < +100). If the attribute is not in the range I want to display an error with the line, where I read the attribute / node / element! Daniel ;) --------------------------- Never change a running system!Daniel S. wrote: What I mean is the current line of a xml node / element in the xml file, like the get_line() function of the IXMLDOMParseError return. Do not confuse the parser error messages that help identify where an error occurs by referencing the line in the file that contains the xml file with how the DOM is structured. All ascii data (non attribute values, comments, processing instructions, etc) is text nodes in the the DOM (line feeds etc. inlcuded) To get the value of an attribute node: hr = pIXMLDOMElement->getAttribute(bstrAttributeName, &varValue); see "IXMLDOMAttribute" in the MSXML 4 help file for the above code sample. YOu need to get the root node and then work your way down the child nodes handling them as appropriate. "I will find a new sig someday."
-
Have you considered using a schema to enforce your data type and valid ranges? Going in that direction may be a lot easier since you basically let the XML parser validate all of your data.
Do you have any sample how I can tell the MSXML DOM parser how to valid my XML file? Daniel ;) --------------------------- Never change a running system!