Jump to content
Xtreme .Net Talk

apdant

Members
  • Posts

    8
  • Joined

  • Last visited

About apdant

  • Birthday 09/30/1980

Personal Information

  • Occupation
    Programmer
  • Visual Studio .NET Version
    Visual Studio .NET Professional
  • .NET Preferred Language
    VB.NET

apdant's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I seem to have solved the problem which was actually not related to the code at all... the XML document was being saved off in Word 2003, which added a ton of formatting to it. This formatting for some reason totally ruined the program. I rewrote the XML document and saved it in plain text and the program ran fine. Thanks for the help guys. :)
  2. Still no luck, but I have been playing with XmlTextReader and manually parsing the values. It's messy, but I cannot seem to get SelectSingleNode to work.
  3. I have been using the sample XML file from the MSDN help, to test. I have tried everything I can think of, here are a couple examples I have tried: dim doc as XmlDocument = New XmlDocument() doc.Load("C:\test.xml") dim root as XmlNode = doc.DocumentElement root.SelectSingleNode("descendant::book[author/last-name='Austen']") root.SelectSingleNode("//book") Here is the XML code. <?xml version="1.0"?> <!-- A fragment of a book store inventory database --> <bookstore xmlns:bk="urn:samples"> <book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8"> <title>Pride And Prejudice</title> <author> <first-name>Jane</first-name> <last-name>Austen</last-name> </author> <price>24.95</price> </book> <book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1"> <title>The Handmaid's Tale</title> <author> <first-name>Margaret</first-name> <last-name>Atwood</last-name> </author> <price>29.95</price> </book> <book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6"> <title>Emma</title> <author> <first-name>Jane</first-name> <last-name>Austen</last-name> </author> <price>19.95</price> </book> <book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3"> <title>Sense and Sensibility</title> <author> <first-name>Jane</first-name> <last-name>Austen</last-name> </author> <price>19.95</price> </book> </bookstore>
  4. That is exactly what is happening Bucky... it returns "Nothing" to the XmlNode object, and the .InnerText property errors the program out. This is assuming that I am trying to use SelectSingleNode/SelectNodes.
  5. It only returns information if I use doc.DocumentElement to set the root. Then I can get some values from FirstChild & LastChild, but it will not let me select an individual node or list of nodes. So I can select the root value, which shows that I have access to the file... but I cannot select a specific node or value.
  6. Bucky, you are right the error handling was very odd, but as I was trying something from an example I had left it virtually untouched on my first attempt. The first attempt worked, so I recoded it from scratch... but it did not return a value. I reverted to the "odd" sample code and no longer get anything from that now! I tried your snippet and the node is still not found. SelectSingleNode does not seem inclined to actually return the node, so it sets the object to "Nothing".
  7. I did that and got header information (<author>Aaron P. Dant</author> etc) ... I am sure that I have access to the .XML file, I just can't seem to make it return a specific node.
  8. Hello all, I have been lurking for a few months around the forums and coding quietly in a dark corner, but recently I have hit a problem I just can't seem to solve. I am writing an application in VB.NET, and attempting to read in configuration information from a .XML file. I read through the MSDN samples and it seemed extremely straightforward, but when I tried to make it work I ran into problems. I took a small code sample from these forums to read in the value. (slightly modified) ---------------------------------------------------------------- Function GetValue(ByVal key as String) As String Try Dim xmlDoc As New XmlDocument() xmlDoc.Load("C:\test.xml") Return xmlDoc.SelectSingleNode("//" & key).InnerText Catch ex As Exception("Error reading file: test.xml", ex) End Try End Function ---------------------------------------------------------------- The first time I tried it, the code returned a value, and everything seemed to work fine. I came back into work the next day, and as things often go... I changed something and it refuses to work now. I have tried using the MSDN samples for the .XML file to make sure my formatting on the file is correct, I have tried using SelectSingleNode, and SelectNodes, wrote different code several times, but both methods return a null value. I can assign a variable to the root and access the file: ----------------------------------------------------------------- Dim doc As XmlDocument = New XmlDocument() doc.Load("C:\test.xml") Dim root As XmlNode = doc.DocumentElement msgbox(root.FirstChild.InnerText) ----------------------------------------------------------------- This tells me that I have accessed the .XML file, I can see the data inside it, and I can manuever the values. When I try to select a specific node using SelectSingleNode/SelectNodes however, I get a null value regardless of what I put in the XPath. I have tried everything I can think of at this point... and I'm basically out of ideas. I appreciate any ideas you have! Aaron
×
×
  • Create New...