Re: Deserialize from SelectSingleNode
From: Geoff (geoffbishop_at_gmail.com)
Date: 11/19/04
- Next message: James Ankrom: "Variety of XML questions;"
- Previous message: Victor Hadianto: "Re: array to xml"
- In reply to: Derek Harmon: "Re: Deserialize from SelectSingleNode"
- Next in thread: Geoff: "Re: Deserialize from SelectSingleNode"
- Messages sorted by: [ date ] [ thread ]
Date: 19 Nov 2004 07:51:51 -0800
Derek, thank you so much for the excellent response. You are a
gentleman and a scholar. You have confirmed for me that my approach
should work, but I'm still having trouble, I think because of
namespaces declared in the XML file. Can you expand your example a
bit to account for a default namespace in the XML file? Or, can you
tell me what might be wrong with my code, below?
The "deserialize" statement gives me the following error:
There is an error in the XML document. --> <FIELDED_ADDRESS
xmlns='http://www.telcordia.com/IDN/ELMS6'> was not expected.
"FIELDED_ADDRESS" is the name of the node I'm trying to
select/deserialize.
"http://www.telcordia.com/IDN/ELMS6" is a namespace declared in the
XML file.
My code looks like this:
XmlDocument ResponseDocument = new XmlDocument();
ResponseDocument.Load @"C:\MyFile.xml");
NamespaceManager = new
XmlNamespaceManager(ResponseDocument.NameTable);
NamespaceManager.AddNamespace("p",
"http://www.telcordia.com/IDN/ELMS6");
XPathQuery = @"//p:FIELDED_ADDRESS";
XmlNode AddressNode = ResponseDocument.SelectSingleNode(XPathQuery,
NamespaceManager);
if (AddressNode != null)
{
ALTERNATIVE_ADDRESSFIELDED_ADDRESS FieldedAddress;
XmlNodeReader NodeReader = new XmlNodeReader(AddressNode);
XmlSerializer Serializer = new
XmlSerializer(typeof(ALTERNATIVE_ADDRESSFIELDED_ADDRESS),
"http://www.telcordia.com/IDN/ELMS6");
FieldedAddress = Serializer.Deserialize(NodeReader) as
ALTERNATIVE_ADDRESSFIELDED_ADDRESS;
}
My XML file looks like this:
<?xml version="1.0" ?>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<Object Id="pp">
<ADDRESS_VALIDATION_OUTPUT
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.telcordia.com/IDN/ELMS6"
version="ELMS6_ADDRESS_VALIDATION_OUTPUT_v2-0"
xsi:schemaLocation="http://www.telcordia.com/IDN/ELMS6
ADDRESS_VALIDATION_OUTPUT.xsd">
<COMMON_QUERY_RSP></COMMON_QUERY_RSP>
<ALTERNATIVE_ADDRESS_INFORMATION_LIST>
<ALTERNATIVE_ADDRESS_INFORMATION>
<ALTERNATIVE_ADDRESS>
<FIELDED_ADDRESS>
<SANO>1445</SANO>
<SATH>DR</SATH>
<SASN>MONROE</SASN>
<SASS>NE</SASS>
<LD3>APT</LD3>
<LV3>C-27</LV3>
<CITY>ATLANTA</CITY>
<STATE>GA</STATE>
</FIELDED_ADDRESS>
</ALTERNATIVE_ADDRESS>
</ALTERNATIVE_ADDRESS_INFORMATION>
</ALTERNATIVE_ADDRESS_INFORMATION_LIST>
</ADDRESS_VALIDATION_OUTPUT>
</Object>
</Signature>
- Next message: James Ankrom: "Variety of XML questions;"
- Previous message: Victor Hadianto: "Re: array to xml"
- In reply to: Derek Harmon: "Re: Deserialize from SelectSingleNode"
- Next in thread: Geoff: "Re: Deserialize from SelectSingleNode"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|