Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. How to get the current line of a xml element / node?

How to get the current line of a xml element / node?

Scheduled Pinned Locked Moved XML / XSL
questionhtmlxmltutorial
6 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Strigl
    wrote on last edited by
    #1

    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!

    M 1 Reply Last reply
    0
    • D Daniel Strigl

      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!

      M Offline
      M Offline
      Michael A Barnhart
      wrote on last edited by
      #2

      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."

      D 1 Reply Last reply
      0
      • M Michael A Barnhart

        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."

        D Offline
        D Offline
        Daniel Strigl
        wrote on last edited by
        #3

        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. 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!

        J M 2 Replies Last reply
        0
        • D Daniel Strigl

          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. 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!

          J Offline
          J Offline
          John M 0
          wrote on last edited by
          #4

          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.

          D 1 Reply Last reply
          0
          • D Daniel Strigl

            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. 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!

            M Offline
            M Offline
            Michael A Barnhart
            wrote on last edited by
            #5

            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."

            1 Reply Last reply
            0
            • J John M 0

              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.

              D Offline
              D Offline
              Daniel Strigl
              wrote on last edited by
              #6

              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!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups