Hello once again!
It's probably a simple question (again), but I've been having some trouble with parsing XML documents. All I need to do is get the text value in a Node, but I can't seem to find a method/property for doing so. The XML DOM should have a property for Nodes called "nodeValue", but Nimrod doesn't seem to have one. The xmltree module has a "innerText()" function, but it works with a PXmlNode instead of a PNode.
The closest I have is this:
# Create the XML.
var doc : PDocument = loadXML(response)
# Get the element.
var node : PNode = getElementsByTagName(doc, "user")[0]
# Get the info.
var userName : string = innerText(node.firstChild)
...but this causes an error for the above reason. Is there a way to convert between them, or is there a simpler way that I could use?
Any help would be greatly appreciated!
import xmltree, xmlparser
let doc = loadXml("fromfile.xml")
let elem = doc.findAll("user")[0]
let userName = elem.innerText
I never use xmldom as the DOM is a foolish design.
Ah, that's it. I was using the loadXML() function from the xmldomparser module.
Thanks so much!
Having slight problems again, but with a different thing this time.
When trying to parse XML, I'm getting this error message:
Traceback (most recent call last)
noaa.nim(74) noaa
noaa.nim(36) getWeather
xmlparser.nim(126) parseXml
xmlparser.nim(24) raiseInvalidXml
Error: unhandled exception: unknown_html_doc(2, 55) Error: <some_tag> expected [EInvalidXml]
...which I don't understand, because as far as I can tell this document is perfectly well formed. Even more confusingly, there is no tag in the document called "some_tag". Is this an internal thing that the module uses?
Here's an example of the format of a document that I'm trying to get data out of: http://pastebin.com/NbcBNDwH
Looks like the problem is the second line: <?xml-stylesheet href="latest_ob.xsl" type="text/xsl"?>
Parser bug I guess.
EDIT: Try it now, I fixed it here.
Huh, removing that line appears to have worked. Thanks for the help!
EDIT: posted before seeing your edit, I'll check while leaving that line in
EDIT 2: works now, thanks again!