loading an xml document from file vs. memory stream

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default loading an xml document from file vs. memory stream

    Hello,

    I need to read am xml node using an xmlNodeReader and selectSingleNode. This
    works fine when I save the file first and then use xmlDocument.load(uri),
    with the uri the location of the saved xml file. But when I try to load the
    xml document by passing the xmlDocument.load method a memory stream I get
    "root element is missing". When I convert the stream to a string using

    Dim theEncoding As New System.Text.UTF8Encoding
    Dim str As String = theEncoding.GetString(ms.GetBuffer)

    the xml looks like this: (Removed text was not removed in the snippet)

    <?xml version="1.0"?>
    <Administrative xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.removed/XMLSchemas/removed/schema.xsd">
    <CourtCode>1111</CourtCode>
    <ReportYear>2005</ReportYear>
    <ReportQuarter>3</ReportQuarter>
    <PreparerName>asdf</PreparerName>
    <PreparerPhone>3333</PreparerPhone>
    <Clerk>false</Clerk>
    </Administrative>

    and this is the same as in the saved xml file that loads fine:

    "<Administrative>
    <CourtCode>8888</CourtCode>
    <Password>password</Password>
    <ReportYear>2005</ReportYear>
    <ReportQuarter>4</ReportQuarter>
    <PreparerName>asdf</PreparerName>
    <PreparerPhone>4444444444</PreparerPhone>
    <Clerk>false</Clerk>
    </Administrative>"

    except for the namespace attributes. So the presence of those, which results
    from loading the xml document from a memory stream rather than from a saved
    file, seems to cause the "root element missing" exception to be thrown.

    How can I prevent the namespace attributes from appearing and causing this
    problem? Or is the a better way to load the file for node reading without
    first saving it?

    Thank you,

    John Hopper
    John Hopper Guest

  2. Similar Questions and Discussions

    1. Loading SWF from Memory Stream
      Hi, I'm using the ShockwaveFlash ActiveX control in a VB.NET Windows Forms application and i'm wondering. Is it possible to load an SWF file...
    2. writing an xml document to output stream (soap)
      I am getting an error on writing an xml document out to the output stream (soapOutputStream). The xml doc is perfectly formed, but when I use the...
    3. #24524 [Fbk->Csd]: failed to open stream: Cannot allocate memory
      ID: 24524 User updated by: jccl at infoquality dot inf dot br Reported By: jccl at infoquality dot inf dot br -Status: ...
    4. #24524 [NoF->Opn]: failed to open stream: Cannot allocate memory
      ID: 24524 User updated by: jccl at infoquality dot inf dot br Reported By: jccl at infoquality dot inf dot br -Status: ...
  3. #2

    Default RE: loading an xml document from file vs. memory stream

    When I try:

    Dim buf As Byte() = System.Text.UTF8Encoding.UTF8.GetBytes(oReport.Out erXml)
    Dim ms As New MemoryStream(buf)
    Dim myXmlDataDoc As XmlDataDocument = New XmlDataDocument
    myXmlDataDoc.Load(ms)

    I get

    Object reference not set to an instance of an object.



    "John Hopper" wrote:
    > Hello,
    >
    > I need to read am xml node using an xmlNodeReader and selectSingleNode. This
    > works fine when I save the file first and then use xmlDocument.load(uri),
    > with the uri the location of the saved xml file. But when I try to load the
    > xml document by passing the xmlDocument.load method a memory stream I get
    > "root element is missing". When I convert the stream to a string using
    >
    > Dim theEncoding As New System.Text.UTF8Encoding
    > Dim str As String = theEncoding.GetString(ms.GetBuffer)
    >
    > the xml looks like this: (Removed text was not removed in the snippet)
    >
    > <?xml version="1.0"?>
    > <Administrative xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xmlns="http://www.removed/XMLSchemas/removed/schema.xsd">
    > <CourtCode>1111</CourtCode>
    > <ReportYear>2005</ReportYear>
    > <ReportQuarter>3</ReportQuarter>
    > <PreparerName>asdf</PreparerName>
    > <PreparerPhone>3333</PreparerPhone>
    > <Clerk>false</Clerk>
    > </Administrative>
    >
    > and this is the same as in the saved xml file that loads fine:
    >
    > "<Administrative>
    > <CourtCode>8888</CourtCode>
    > <Password>password</Password>
    > <ReportYear>2005</ReportYear>
    > <ReportQuarter>4</ReportQuarter>
    > <PreparerName>asdf</PreparerName>
    > <PreparerPhone>4444444444</PreparerPhone>
    > <Clerk>false</Clerk>
    > </Administrative>"
    >
    > except for the namespace attributes. So the presence of those, which results
    > from loading the xml document from a memory stream rather than from a saved
    > file, seems to cause the "root element missing" exception to be thrown.
    >
    > How can I prevent the namespace attributes from appearing and causing this
    > problem? Or is the a better way to load the file for node reading without
    > first saving it?
    >
    > Thank you,
    >
    > John Hopper
    John Hopper Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139