Question Extract text from a string

Jimmy22

Member
Joined
Mar 27, 2008
Messages
15
Programming Experience
Beginner
Hi there,

How would you guys tackle this little problem i have a string called strXML which hold this text:

PHP:
<?xml version="1.0"?>
<one:Notebooks xmlns:one="http://schemas.microsoft.com/office/onenote/2007/onenote"><one:Notebook name="Work Notebook" nickname="Work Notebook" ID="{5DB5E9BD-9929-4587-AC79-42750C130E77}{1}{B0}" path="C:\Documents and Settings\James\My Documents\OneNote Notebooks\Work Notebook" lastModifiedTime="2007-10-04T10:54:47.000Z" color="#FFD869"/><one:Notebook name="Personal Notebook" nickname="Personal Notebook" ID="{00A1E767-7CB8-4053-A286-2AAD7BEA5B65}{1}{B0}" path="C:\Documents and Settings\James\My Documents\OneNote Notebooks\Personal Notebook" lastModifiedTime="2007-10-04T10:54:47.000Z" color="#B7C997"/><one:Notebook name="OneNote 2007 Guide" nickname="OneNote 2007 Guide" ID="{A96C7D4F-E30B-4D41-A523-2E1C577827DB}{1}{B0}" path="C:\Documents and Settings\James\My Documents\OneNote Notebooks\OneNote 2007 Guide" lastModifiedTime="2007-10-04T10:54:48.000Z" color="#EE9597"/><one:Notebook name="Goldfield Shared Onenote" nickname="Goldfield Shared Onenote" ID="{937C41C9-FED5-4441-B9B1-B0D80163804E}{1}{B0}" path="Z:\OneNote Shares\Goldfield Shared Onenote" lastModifiedTime="2009-11-12T10:58:51.000Z" color="#FFD869"/><one:Notebook name="CURRENT INSTALL INFO" nickname="CURRENT INSTALL INFO" ID="{9D578F0E-99DA-4BDF-A241-0FEB410B27EC}{1}{B0}" path="Z:\OneNote Shares\CURRENT INSTALL INFO" lastModifiedTime="2009-11-05T13:11:59.000Z" color="#ADE792"/><one:Notebook name="GOLDFIELD CUSTOMERS" nickname="GOLDFIELD CUSTOMERS" ID="{672F4DEA-BF8F-4D6E-B3DC-CC9E04A6188C}{1}{B0}" path="\\SERVER01\Customer Data\OneNote Shares\GOLDFIELD CUSTOMERS" lastModifiedTime="2009-11-19T14:52:20.000Z" color="#EE9597" isCurrentlyViewed="true"/><one:UnfiledNotes ID="{F8362788-D05B-4672-90B3-0F27B9FB5A16}{1}{B0}"/><one:OpenSections ID="{316B0219-E9D2-4616-AF5E-C46AAADDCD1E}{1}{B0}"/></one:Notebooks>

I would like to extract the ID={xxxxxxxxxxxxxx xxxxxxxx} and the Path="z:\xxx xxx into 2 different combo boxs how would you do this.

All the help really appriciated

Cheers J
 
Any chance you could redo the xml so it's not all in one line? You could loop thru the elements and extract the element's attribute.value .
 
Here is the XML better formatted than before, :D

<?xml version="1.0"?>
<one:Notebooks xmlns:eek:ne="http://schemas.microsoft.com/office/onenote/2007/onenote"><one:Notebook name="Work Notebook" nickname="Work Notebook" ID="{5DB5E9BD-9929-4587-AC79-42750C130E77}{1}{B0}" path="C:\Documents and Settings\James\My Documents\OneNote Notebooks\Work Notebook" lastModifiedTime="2007-10-04T10:54:47.000Z" color="#FFD869"/><one:Notebook name="Personal Notebook" nickname="Personal Notebook" ID="{00A1E767-7CB8-4053-A286-2AAD7BEA5B65}{1}{B0}" path="C:\Documents and Settings\James\My Documents\OneNote Notebooks\Personal Notebook" lastModifiedTime="2007-10-04T10:54:47.000Z" color="#B7C997"/><one:Notebook name="OneNote 2007 Guide" nickname="OneNote 2007 Guide" ID="{A96C7D4F-E30B-4D41-A523-2E1C577827DB}{1}{B0}" path="C:\Documents and Settings\James\My Documents\OneNote Notebooks\OneNote 2007 Guide" lastModifiedTime="2007-10-04T10:54:48.000Z" color="#EE9597"/><one:Notebook name="Goldfield Shared Onenote" nickname="Goldfield Shared Onenote" ID="{937C41C9-FED5-4441-B9B1-B0D80163804E}{1}{B0}" path="Z:\OneNote Shares\Goldfield Shared Onenote" lastModifiedTime="2009-11-12T10:58:51.000Z" color="#FFD869"/><one:Notebook name="CURRENT INSTALL INFO" nickname="CURRENT INSTALL INFO" ID="{9D578F0E-99DA-4BDF-A241-0FEB410B27EC}{1}{B0}" path="Z:\OneNote Shares\CURRENT INSTALL INFO" lastModifiedTime="2009-11-05T13:11:59.000Z" color="#ADE792"/><one:Notebook name="GOLDFIELD CUSTOMERS" nickname="GOLDFIELD CUSTOMERS" ID="{672F4DEA-BF8F-4D6E-B3DC-CC9E04A6188C}{1}{B0}" path="\\SERVER01\Customer Data\OneNote Shares\GOLDFIELD CUSTOMERS" lastModifiedTime="2009-11-19T14:52:20.000Z" color="#EE9597" isCurrentlyViewed="true"/><one:UnfiledNotes ID="{F8362788-D05B-4672-90B3-0F27B9FB5A16}{1}{B0}"/><one:OpenSections ID="{316B0219-E9D2-4616-AF5E-C46AAADDCD1E}{1}{B0}"/></one:Notebooks>

You could loop thru the elements and extract the element's attribute.value .

I will look into the attribute.value syntax
 
VB.NET:
Dim doc As New Xml.XmlDocument
doc.LoadXml(strXml) 'or doc.Load(url)
Dim ns As New Xml.XmlNamespaceManager(doc.NameTable)
ns.AddNamespace("one", "http://schemas.microsoft.com/office/onenote/2007/onenote")
For Each notebook As Xml.XmlNode In doc.SelectNodes("one:Notebooks/one:Notebook", ns)
    Me.ComboBox1.Items.Add(notebook.Attributes("ID").Value)
    Me.ComboBox1.Items.Add(notebook.Attributes("path").Value)
Next
 
Back
Top