Re: Deserialize from SelectSingleNode

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Geoff (geoffbishop_at_gmail.com)
Date: 11/19/04


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>



Relevant Pages

  • Re: XML
    ... > Thanks for response ... > I have attached both the xsd and the sample ... I checked the xml file you've attached, ...
    (microsoft.public.fox.programmer.exchange)
  • XML Posting to Web Service Problems
    ... It posts the XML file to the web ... service without a problem, but when I go to get the response, it times ... 'Set path of xml file to pass via HTTP ... Dim clsDocument As New System.Xml.XmlDocument ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: XML parsing with Javascript
    ... authentication succeeds the service responds with an xml file. ... the request, the open method takes username and password as optional ... Since the sandbox model doesn't allow access to this XML response, ... And then parse the response at server before returning output ...
    (comp.lang.javascript)
  • Castor XML Question: How to ignore wrapping elements
    ... I have an xml file that looks something like: ... I am trying to map <Invoice> to my Invoice.java class. ... Castor to ignore the outer <Response> tag? ...
    (comp.lang.java.programmer)