Extract Strings

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

Following is the string ...

<ADDRESSINFO name = "Cedar Ave" no = "21123" attrib ="visible">
<HOUSE name ="main" type ="1" value ="2200"/>
<HOUSE name ="slide" type ="12" value ="123"/>
<HOUSE name ="major" type ="1" value ="1234"/>
<HOUSE name ="branch" type ="1" value ="31980"/>
</ADDRESSINFO>

<ADDRESSINFO name = "5th Street" no = "65653" attrib ="visible">
<HOUSE name ="minor" type ="2" value ="43121"/>
<HOUSE name ="corner" type ="90" value ="65109"/>
<HOUSE name ="tree" type ="22" value ="7"/>
<HOUSE name ="walk" type ="2" value ="721"/>
</ADDRESSINFO>

.....................................................
....................................................// text goes on like this


I want to give the name value in ADDRESSINFO tag and get all the House names
of that particular Addressin an array. How can I do this?

eg., If I give 5th street as the input, I should get minor, corner, tree,
walk in an array .

Any help would be greatly appreciated!

Regards
Steven
 
Ok, well this isn't an ordinary string, its the string representation of an
Xml Document.
So you would load this into a new XmlDocument
instance
and use Xpath query methods

XmlNodelist nodList1 = xmlDoc.selectNodes("//ADDRESSINFO[@name='5th
Street']/HOUSE")
or something similar. (Sorry my Xpath is rusty).
Peter
 
Keep in mind it's not well-formed XML (needs a root node), but assuming this
is only a partial XML file and there is a root node, after you perform your
XPath query on it, you can iterate the nodes like this:

foreach XmlNode xn in nodList1
{
// Use the Attributes[ ] property of xn to access the name,
// type and value attributes in your XML Nodes
}

Peter Bromberg said:
Ok, well this isn't an ordinary string, its the string representation of
an Xml Document.
So you would load this into a new XmlDocument
instance
and use Xpath query methods

XmlNodelist nodList1 = xmlDoc.selectNodes("//ADDRESSINFO[@name='5th
Street']/HOUSE")
or something similar. (Sorry my Xpath is rusty).
Peter

Steven said:
Following is the string ...

<ADDRESSINFO name = "Cedar Ave" no = "21123" attrib ="visible">
<HOUSE name ="main" type ="1" value ="2200"/>
<HOUSE name ="slide" type ="12" value ="123"/>
<HOUSE name ="major" type ="1" value ="1234"/>
<HOUSE name ="branch" type ="1" value ="31980"/>
</ADDRESSINFO>

<ADDRESSINFO name = "5th Street" no = "65653" attrib ="visible">
<HOUSE name ="minor" type ="2" value ="43121"/>
<HOUSE name ="corner" type ="90" value ="65109"/>
<HOUSE name ="tree" type ="22" value ="7"/>
<HOUSE name ="walk" type ="2" value ="721"/>
</ADDRESSINFO>

....................................................
...................................................// text goes on like
this


I want to give the name value in ADDRESSINFO tag and get all the House
names of that particular Addressin an array. How can I do this?

eg., If I give 5th street as the input, I should get minor, corner, tree,
walk in an array .

Any help would be greatly appreciated!

Regards
Steven
 
oops, forgot parens (too much darn VB programming at work):

foreach (XmlNode xn in nodList1)
{
// Use the Attributes[ ] property of xn to access the name,
// type and value attributes in your XML Nodes
}

Peter Bromberg said:
Ok, well this isn't an ordinary string, its the string representation of
an Xml Document.
So you would load this into a new XmlDocument
instance
and use Xpath query methods

XmlNodelist nodList1 = xmlDoc.selectNodes("//ADDRESSINFO[@name='5th
Street']/HOUSE")
or something similar. (Sorry my Xpath is rusty).
Peter

Steven said:
Following is the string ...

<ADDRESSINFO name = "Cedar Ave" no = "21123" attrib ="visible">
<HOUSE name ="main" type ="1" value ="2200"/>
<HOUSE name ="slide" type ="12" value ="123"/>
<HOUSE name ="major" type ="1" value ="1234"/>
<HOUSE name ="branch" type ="1" value ="31980"/>
</ADDRESSINFO>

<ADDRESSINFO name = "5th Street" no = "65653" attrib ="visible">
<HOUSE name ="minor" type ="2" value ="43121"/>
<HOUSE name ="corner" type ="90" value ="65109"/>
<HOUSE name ="tree" type ="22" value ="7"/>
<HOUSE name ="walk" type ="2" value ="721"/>
</ADDRESSINFO>

....................................................
...................................................// text goes on like
this


I want to give the name value in ADDRESSINFO tag and get all the House
names of that particular Addressin an array. How can I do this?

eg., If I give 5th street as the input, I should get minor, corner, tree,
walk in an array .

Any help would be greatly appreciated!

Regards
Steven
 
Back
Top